/**
* Is thrown when an allocation limit is exceeded.
- *
- * @since Android 1.0
+ *
+ * @deprecated this is an internal Dalvik class that is not appropriate for
+ * general use. It will be removed from the public API in a future release.
*/
public class AllocationLimitError extends VirtualMachineError {
/**
/**
* Is thrown when the VM identifies a potential deadlock.
- *
- * @since Android 1.0
+ *
+ * @deprecated this is an internal Dalvik class that is not appropriate for
+ * general use. It will be removed from the public API in a future release.
*/
public class PotentialDeadlockError extends VirtualMachineError {
/**
/**
* Is thrown when the VM determines that a DEX file's cache is out of date, and
* that there is no way to recreate it.
+ *
+ * @deprecated this is an internal Dalvik class that is not appropriate for
+ * general use. It will be removed from the public API in a future release.
*/
public class StaleDexCacheError extends VirtualMachineError {
/**
* call into this class with an appropriate base directory during its
* startup, as a reasonably easy way to get the standard property
* <code>java.io.tmpdir</code> to point at something useful.
- *
- * @since Android 1.0
+ *
+ * @deprecated this is an internal Dalvik class that is not appropriate for
+ * general use. It will be removed from the public API in a future release.
*/
public class TemporaryDirectory {
/** system property name for the temporary directory */
/**
* Induces optimization/verification of a set of DEX files.
*
- * TODO: This class is public, so SystemServer can access it. This is NOT
- * the correct long-term solution; once we have a real installer and/or
- * dalvik-cache manager, this class should be removed.
- *
- * @cts See to-do about removing this class...
- *
- * @since Android 1.0
+ * @deprecated this is an internal Dalvik class that is not appropriate for
+ * general use. It will be removed from the public API in a future release.
*/
public class TouchDex {
* <code>android.os.Debug</code>.
*
* @cts Please complete the spec.
- *
- * @since Android 1.0
+ *
+ * @deprecated this is an internal Dalvik class that is not appropriate for
+ * general use. It will be removed from the public API in a future release.
*/
public final class VMDebug {
/**
* Provides an interface to VM-global, Dalvik-specific features.
* An application cannot create its own Runtime instance, and must obtain
* one from the getRuntime method.
- *
+ *
+ * @deprecated this is an internal Dalvik class that is not appropriate for
+ * general use. It will be removed from the public API in a future release.
+ *
* @since Android 1.0
*/
public final class VMRuntime {
* be resized so that (size of live objects) / (size of heap) is
* equal to this number.
*
+ * <p>This is only a hint to the garbage collector and may be ignored.
+ *
* @param newTarget the new suggested ideal heap utilization.
* This value may be adjusted internally.
* @return the previous ideal heap utilization
* size, the maximum size will be used. If size is zero
* or negative, the minimum size constraint will be removed.
*
- * Synchronized to make the order of the exchange reliable.
+ * <p>Synchronized to make the order of the exchange reliable.
+ *
+ * <p>This is only a hint to the garbage collector and may be ignored.
*
* @param size the new suggested minimum heap size, in bytes
* @return the old minimum heap size value
/**
* Returns the number of externally-allocated bytes being tracked by
* trackExternalAllocation/Free().
- *
+ *
* @return the number of bytes
*/
public native long getExternalBytesAllocated();
/**
* Provides a limited interface to the Dalvik VM stack. This class is mostly
* used for implementing security checks.
- *
- * @since Android 1.0
+ *
+ * @deprecated this is an internal Dalvik class that is not appropriate for
+ * general use. It will be removed from the public API in a future release.
*/
public final class VMStack {
/**
* Provides access to the Dalvik "zygote" feature, which allows a VM instance to
* be partially initialized and then fork()'d from the partially initialized
* state.
- *
- * @since Android 1.0
+ *
+ * @deprecated this is an internal Dalvik class that is not appropriate for
+ * general use. It will be removed from the public API in a future release.
*/
public class Zygote {
/*
}
if (fieldDesc != null) {
if (toSet != null) {
- Class<?> fieldType = fieldDesc.getType();
+ // BEGIN android-changed
+ // Get the field type from the local field rather than
+ // from the stream's supplied data. That's the field
+ // we'll be setting, so that's the one that needs to be
+ // validated.
+ Class<?> fieldType = field.getTypeInternal();
+ // END android-added
Class<?> valueType = toSet.getClass();
if (!fieldType.isAssignableFrom(valueType)) {
throw new ClassCastException(Msg.getString(
private boolean isClosed = false;
/**
- * The circular buffer through which data is passed.
+ * The circular buffer through which data is passed. Data is read from the
+ * range {@code [out, in)} and written to the range {@code [in, out)}.
+ * Data in the buffer is either sequential: <pre>
+ * { - - - X X X X X X X - - - - - }
+ * ^ ^
+ * | |
+ * out in</pre>
+ * ...or wrapped around the buffer's end: <pre>
+ * { X X X X - - - - - - - - X X X }
+ * ^ ^
+ * | |
+ * in out</pre>
+ * When the buffer is empty, {@code in == -1}. Reading when the buffer is
+ * empty will block until data is available. When the buffer is full,
+ * {@code in == out}. Writing when the buffer is full will block until free
+ * space is available.
*/
protected byte buffer[];
throw new IOException(Msg.getString("K0075")); //$NON-NLS-1$
}
- if (lastWriter != null && !lastWriter.isAlive() && (in < 0)) {
- // KA030=Write end dead
- throw new IOException(Msg.getString("KA030")); //$NON-NLS-1$
- }
+ // BEGIN android-removed
+ // eagerly throwing prevents checking isClosed and returning normally
+ // if (lastWriter != null && !lastWriter.isAlive() && (in < 0)) {
+ // // KA030=Write end dead
+ // throw new IOException(Msg.getString("KA030")); //$NON-NLS-1$
+ // }
+ // END android-removed
+
/**
* Set the last thread to be reading on this PipedInputStream. If
* lastReader dies while someone is waiting to write an IOException of
throw new InterruptedIOException();
}
- byte result = buffer[out++];
+ // BEGIN android-changed
+ int result = buffer[out++] & 0xff;
if (out == buffer.length) {
out = 0;
}
in = -1;
out = 0;
}
- return result & 0xff;
+
+ // let blocked writers write to the newly available buffer space
+ notifyAll();
+
+ return result;
+ // END android-changed
}
/**
throw new IOException(Msg.getString("K0075")); //$NON-NLS-1$
}
- if (lastWriter != null && !lastWriter.isAlive() && (in < 0)) {
- // KA030=Write end dead
- throw new IOException(Msg.getString("KA030")); //$NON-NLS-1$
- }
+ // BEGIN android-removed
+ // eagerly throwing prevents checking isClosed and returning normally
+ // if (lastWriter != null && !lastWriter.isAlive() && (in < 0)) {
+ // // KA030=Write end dead
+ // throw new IOException(Msg.getString("KA030")); //$NON-NLS-1$
+ // }
+ // END android-removed
/**
* Set the last thread to be reading on this PipedInputStream. If
throw new InterruptedIOException();
}
- int copyLength = 0;
- /* Copy bytes from out to end of buffer first */
+ // BEGIN android-changed
+ int totalCopied = 0;
+
+ // copy bytes from out thru the end of buffer
if (out >= in) {
- copyLength = count > (buffer.length - out) ? buffer.length - out
- : count;
- System.arraycopy(buffer, out, bytes, offset, copyLength);
- out += copyLength;
+ int leftInBuffer = buffer.length - out;
+ int length = leftInBuffer < count ? leftInBuffer : count;
+ System.arraycopy(buffer, out, bytes, offset, length);
+ out += length;
if (out == buffer.length) {
out = 0;
}
in = -1;
out = 0;
}
+ totalCopied += length;
}
- /*
- * Did the read fully succeed in the previous copy or is the buffer
- * empty?
- */
- if (copyLength == count || in == -1) {
- return copyLength;
+ // copy bytes from out thru in
+ if (totalCopied < count && in != -1) {
+ int leftInBuffer = in - out;
+ int leftToCopy = count - totalCopied;
+ int length = leftToCopy < leftInBuffer ? leftToCopy : leftInBuffer;
+ System.arraycopy(buffer, out, bytes, offset + totalCopied, length);
+ out += length;
+ if (out == in) {
+ // empty buffer
+ in = -1;
+ out = 0;
+ }
+ totalCopied += length;
}
- int bytesCopied = copyLength;
- /* Copy bytes from 0 to the number of available bytes */
- copyLength = in - out > (count - bytesCopied) ? count - bytesCopied
- : in - out;
- System.arraycopy(buffer, out, bytes, offset + bytesCopied, copyLength);
- out += copyLength;
- if (out == in) {
- // empty buffer
- in = -1;
- out = 0;
- }
- return bytesCopied + copyLength;
+ // let blocked writers write to the newly available buffer space
+ notifyAll();
+
+ return totalCopied;
+ // END android-changed
}
/**
if (buffer == null || isClosed) {
throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
}
- if (lastReader != null && !lastReader.isAlive()) {
- throw new IOException(Msg.getString("K0076")); //$NON-NLS-1$
- }
+ // BEGIN android-removed
+ // eagerly throwing causes us to fail even if the buffer's not full
+ // if (lastReader != null && !lastReader.isAlive()) {
+ // throw new IOException(Msg.getString("K0076")); //$NON-NLS-1$
+ // }
+ // END android-removed
/**
* Set the last thread to be writing on this PipedInputStream. If
* lastWriter dies while someone is waiting to read an IOException of
lastWriter = Thread.currentThread();
try {
while (buffer != null && out == in) {
- notifyAll();
- wait(1000);
+ // BEGIN android-changed
+ // moved has-last-reader-died check to be before wait()
if (lastReader != null && !lastReader.isAlive()) {
throw new IOException(Msg.getString("K0076")); //$NON-NLS-1$
}
+ notifyAll();
+ wait(1000);
+ // END android-changed
}
} catch (InterruptedException e) {
throw new InterruptedIOException();
if (in == buffer.length) {
in = 0;
}
- return;
+
+ // BEGIN android-added
+ // let blocked readers read the newly available data
+ notifyAll();
+ // END android-added
}
}
args = {}
)
public void test_getClassLoader() {
- // this fails if ClassTest.class was loaded by the regular classloader,
- // but passes if it was loaded by the boot class loader.
-
assertEquals(ExtendTestClass.class.getClassLoader(),
PublicTestClass.class.getClassLoader());
System.setSecurityManager(sm);
try {
System.class.getClassLoader();
- } catch (SecurityException e) {
- fail("SecurityException should not be thrown.");
+ fail("SecurityException should be thrown.");
+ } catch (SecurityException expected) {
} finally {
System.setSecurityManager(oldSm);
}
package org.apache.harmony.luni.tests.java.lang;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
-
+import dalvik.annotation.TestTargetNew;
import junit.framework.TestCase;
-import java.io.File;
import java.io.FileDescriptor;
import java.io.FilePermission;
import java.io.IOException;
import java.security.Security;
import java.security.SecurityPermission;
-import tests.support.Support_Exec;
-
/**
* Test case for java.lang.SecurityManager
*/
}
try {
- mutableSM.checkMemberAccess(Object.class, Member.DECLARED);
+ delegateCallToCheckMemberAccess2(Object.class, Member.DECLARED);
fail("SecurityException was not thrown.");
} catch(SecurityException se) {
//expected
}
try {
- mutableSM.checkMemberAccess(null, Member.PUBLIC);
+ delegateCallToCheckMemberAccess2(null, Member.PUBLIC);
fail("NullPointerException was not thrown.");
} catch(NullPointerException npe) {
//expected
}
/**
+ * Don't call checkMemberAccess directly, since we're checking our caller
+ * (and not ourselves). This is necessary for unit tests, since JUnit's
+ * TestCase is usually in the boot classpath for dalvik. This delegating
+ * method corresponds to Class.getDeclared*();
+ */
+ private void delegateCallToCheckMemberAccess2(Class<Object> cls, int type) {
+ delegateCallToCheckMemberAccess1(cls, type);
+ }
+
+ /**
+ * This delegating method corresponds to Class.checkMemberAccess().
+ */
+ private void delegateCallToCheckMemberAccess1(Class<Object> cls, int type) {
+ mutableSM.checkMemberAccess(cls, type);
+ }
+
+ /**
* @tests java.lang.SecurityManager#checkPermission(java.security.Permission)
*/
@TestTargetNew(
import java.util.Collection;
import java.util.Map;
import java.util.Set;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
args = {}
)
public void test_getManifest() throws Exception {
-
- String [] expected = {"plus.bmp", "swt.dll"};
+
//URL u = new URL("jar:"
// + BASE.toString()+"/lf.jar!/swt.dll");
juc = (JarURLConnection) u.openConnection();
Manifest manifest = juc.getManifest();
Map<String, Attributes> attr = manifest.getEntries();
- assertEquals(expected.length, attr.size());
- Set<String> keys = attr.keySet();
- String [] result = new String[expected.length];
- keys.toArray(result);
+ assertEquals(new HashSet<String>(Arrays.asList("plus.bmp", "swt.dll")),
+ attr.keySet());
- for(int i = 0; i < result.length; i++) {
- assertEquals(expected[i], result[i]);
- }
-
//URL invURL = new URL("jar:"
// + BASE.toString()+"/InvalidJar.jar!/Test.class");
}
static BigInteger shiftLeftOneBit(BigInteger source) {
+ // BEGIN android-added
+ source.establishOldRepresentation("BitLevel.shiftLeftOneBit");
+ // END android-added
int srcLen = source.numberLength;
int resLen = srcLen + 1;
int resDigits[] = new int[resLen];