am d987149f: am 3802bbcf: am fe39951e: Values in ZIP files are unsigned.
* commit 'd987149f51ee632735cf359ec25cb6092d73aca0':
Values in ZIP files are unsigned.
diff --git a/dalvik/src/main/java/dalvik/system/DexPathList.java b/dalvik/src/main/java/dalvik/system/DexPathList.java
index 1253223..ba4bb15 100644
--- a/dalvik/src/main/java/dalvik/system/DexPathList.java
+++ b/dalvik/src/main/java/dalvik/system/DexPathList.java
@@ -200,7 +200,7 @@
* up front.
*/
for (File file : files) {
- ZipFile zip = null;
+ File zip = null;
DexFile dex = null;
String name = file.getName();
@@ -213,17 +213,7 @@
}
} else if (name.endsWith(APK_SUFFIX) || name.endsWith(JAR_SUFFIX)
|| name.endsWith(ZIP_SUFFIX)) {
- try {
- zip = new ZipFile(file);
- } catch (IOException ex) {
- /*
- * Note: ZipException (a subclass of IOException)
- * might get thrown by the ZipFile constructor
- * (e.g. if the file isn't actually a zip/jar
- * file).
- */
- System.logE("Unable to open zip file: " + file, ex);
- }
+ zip = file;
try {
dex = loadDexFile(file, optimizedDirectory);
@@ -385,23 +375,53 @@
* Element of the dex/resource file path
*/
/*package*/ static class Element {
- public final File file;
- public final ZipFile zipFile;
- public final DexFile dexFile;
+ private final File file;
+ private final File zip;
+ private final DexFile dexFile;
- public Element(File file, ZipFile zipFile, DexFile dexFile) {
+ private ZipFile zipFile;
+ private boolean init;
+
+ public Element(File file, File zip, DexFile dexFile) {
this.file = file;
- this.zipFile = zipFile;
+ this.zip = zip;
this.dexFile = dexFile;
}
- public URL findResource(String name) {
- if ((zipFile == null) || (zipFile.getEntry(name) == null)) {
+ public synchronized void maybeInit() {
+ if (init) {
+ return;
+ }
+
+ init = true;
+
+ if (zip == null) {
/*
* Either this element has no zip/jar file (first
* clause), or the zip/jar file doesn't have an entry
* for the given name (second clause).
*/
+ return;
+ }
+
+ try {
+ zipFile = new ZipFile(zip);
+ } catch (IOException ioe) {
+ /*
+ * Note: ZipException (a subclass of IOException)
+ * might get thrown by the ZipFile constructor
+ * (e.g. if the file isn't actually a zip/jar
+ * file).
+ */
+ System.logE("Unable to open zip file: " + file, ioe);
+ zipFile = null;
+ }
+ }
+
+ public URL findResource(String name) {
+ maybeInit();
+
+ if (zipFile == null || zipFile.getEntry(name) == null) {
return null;
}
diff --git a/luni/src/main/java/java/math/BigDecimal.java b/luni/src/main/java/java/math/BigDecimal.java
index 335e3bc..426a9d2 100644
--- a/luni/src/main/java/java/math/BigDecimal.java
+++ b/luni/src/main/java/java/math/BigDecimal.java
@@ -25,18 +25,12 @@
import libcore.math.MathUtils;
/**
- * This class represents immutable integer numbers of arbitrary length. Large
- * numbers are typically used in security applications and therefore BigIntegers
- * offer dedicated functionality like the generation of large prime numbers or
- * the computation of modular inverse.
- * <p>
- * Since the class was modeled to offer all the functionality as the {@link Integer}
- * class does, it provides even methods that operate bitwise on a two's
- * complement representation of large integers. Note however that the
- * implementations favors an internal representation where magnitude and sign
- * are treated separately. Hence such operations are inefficient and should be
- * discouraged. In simple words: Do NOT implement any bit fields based on
- * BigInteger.
+ * An immutable arbitrary-precision signed decimal.
+ *
+ * <p>A value is represented by an arbitrary-precision "unscaled value" and a signed 32-bit "scale",
+ * combined thus: {@code unscaled * 10<sup>-scale</sup>}. See {@link #unscaledValue} and {@link #scale}.
+ *
+ * <p>Most operations allow you to supply a {@link MathContext} to specify a desired rounding mode.
*/
public class BigDecimal extends Number implements Comparable<BigDecimal>, Serializable {
@@ -427,9 +421,6 @@
* Constructs a new {@code BigDecimal} instance from a string
* representation.
*
- * @param val
- * string containing the string representation of this {@code
- * BigDecimal}.
* @throws NumberFormatException
* if {@code val} does not contain a valid string representation
* of a big decimal.
@@ -443,9 +434,6 @@
* representation. The result is rounded according to the specified math
* context.
*
- * @param val
- * string containing the string representation of this {@code
- * BigDecimal}.
* @param mc
* rounding mode and precision for the result of this operation.
* @throws NumberFormatException
@@ -558,10 +546,6 @@
/**
* Constructs a new {@code BigDecimal} instance from the given big integer
* {@code val}. The scale of the result is {@code 0}.
- *
- * @param val
- * {@code BigInteger} value to be converted to a {@code
- * BigDecimal} instance.
*/
public BigDecimal(BigInteger val) {
this(val, 0);
@@ -571,9 +555,6 @@
* Constructs a new {@code BigDecimal} instance from the given big integer
* {@code val}. The scale of the result is {@code 0}.
*
- * @param val
- * {@code BigInteger} value to be converted to a {@code
- * BigDecimal} instance.
* @param mc
* rounding mode and precision for the result of this operation.
* @throws ArithmeticException
@@ -589,13 +570,8 @@
/**
* Constructs a new {@code BigDecimal} instance from a given unscaled value
* {@code unscaledVal} and a given scale. The value of this instance is
- * {@code unscaledVal} 10^(-{@code scale}).
+ * {@code unscaledVal * 10<sup>-scale</sup>}).
*
- * @param unscaledVal
- * {@code BigInteger} representing the unscaled value of this
- * {@code BigDecimal} instance.
- * @param scale
- * scale of this {@code BigDecimal} instance.
* @throws NullPointerException
* if {@code unscaledVal == null}.
*/
@@ -610,14 +586,9 @@
/**
* Constructs a new {@code BigDecimal} instance from a given unscaled value
* {@code unscaledVal} and a given scale. The value of this instance is
- * {@code unscaledVal} 10^(-{@code scale}). The result is rounded according
+ * {@code unscaledVal * 10<sup>-scale</sup>). The result is rounded according
* to the specified math context.
*
- * @param unscaledVal
- * {@code BigInteger} representing the unscaled value of this
- * {@code BigDecimal} instance.
- * @param scale
- * scale of this {@code BigDecimal} instance.
* @param mc
* rounding mode and precision for the result of this operation.
* @throws ArithmeticException
@@ -696,16 +667,8 @@
/**
* Returns a new {@code BigDecimal} instance whose value is equal to {@code
- * unscaledVal} 10^(-{@code scale}). The scale of the result is {@code
+ * unscaledVal * 10<sup>-scale</sup>}). The scale of the result is {@code
* scale}, and its unscaled value is {@code unscaledVal}.
- *
- * @param unscaledVal
- * unscaled value to be used to construct the new {@code
- * BigDecimal}.
- * @param scale
- * scale to be used to construct the new {@code BigDecimal}.
- * @return {@code BigDecimal} instance with the value {@code unscaledVal}*
- * 10^(-{@code unscaledVal}).
*/
public static BigDecimal valueOf(long unscaledVal, int scale) {
if (scale == 0) {
@@ -1629,17 +1592,14 @@
}
/**
- * Returns a new {@code BigDecimal} whose value is {@code this ^ n}. The
- * scale of the result is {@code n} times the scales of {@code this}.
- * <p>
- * {@code x.pow(0)} returns {@code 1}, even if {@code x == 0}.
- * <p>
- * Implementation Note: The implementation is based on the ANSI standard
+ * Returns a new {@code BigDecimal} whose value is {@code this<sup>n</sup>}. The
+ * scale of the result is {@code n * this.scale()}.
+ *
+ * <p>{@code x.pow(0)} returns {@code 1}, even if {@code x == 0}.
+ *
+ * <p>Implementation Note: The implementation is based on the ANSI standard
* X3.274-1996 algorithm.
*
- * @param n
- * exponent to which {@code this} is raised.
- * @return {@code this ^ n}.
* @throws ArithmeticException
* if {@code n < 0} or {@code n > 999999999}.
*/
@@ -1657,17 +1617,14 @@
}
/**
- * Returns a new {@code BigDecimal} whose value is {@code this ^ n}. The
+ * Returns a new {@code BigDecimal} whose value is {@code this<sup>n</sup>}. The
* result is rounded according to the passed context {@code mc}.
- * <p>
- * Implementation Note: The implementation is based on the ANSI standard
+ *
+ * <p>Implementation Note: The implementation is based on the ANSI standard
* X3.274-1996 algorithm.
*
- * @param n
- * exponent to which {@code this} is raised.
* @param mc
* rounding mode and precision for the result of this operation.
- * @return {@code this ^ n}.
* @throws ArithmeticException
* if {@code n < 0} or {@code n > 999999999}.
*/
@@ -1791,7 +1748,8 @@
*
* @return {@code -1} if {@code this < 0},
* {@code 0} if {@code this == 0},
- * {@code 1} if {@code this > 0}. */
+ * {@code 1} if {@code this > 0}.
+ */
public int signum() {
if( bitLength < 64) {
return Long.signum( this.smallValue );
@@ -1807,8 +1765,8 @@
/**
* Returns the scale of this {@code BigDecimal}. The scale is the number of
* digits behind the decimal point. The value of this {@code BigDecimal} is
- * the unsignedValue * 10^(-scale). If the scale is negative, then this
- * {@code BigDecimal} represents a big integer.
+ * the {@code unsignedValue * 10<sup>-scale</sup>}. If the scale is negative,
+ * then this {@code BigDecimal} represents a big integer.
*
* @return the scale of this {@code BigDecimal}.
*/
@@ -1858,10 +1816,8 @@
/**
* Returns the unscaled value (mantissa) of this {@code BigDecimal} instance
- * as a {@code BigInteger}. The unscaled value can be computed as {@code
- * this} 10^(scale).
- *
- * @return unscaled value (this * 10^(scale)).
+ * as a {@code BigInteger}. The unscaled value can be computed as
+ * {@code this * 10<sup>scale</sup>}.
*/
public BigInteger unscaledValue() {
return getUnscaledValue();
@@ -1989,17 +1945,13 @@
* Returns a new {@code BigDecimal} instance where the decimal point has
* been moved {@code n} places to the left. If {@code n < 0} then the
* decimal point is moved {@code -n} places to the right.
- * <p>
- * The result is obtained by changing its scale. If the scale of the result
+ *
+ * <p>The result is obtained by changing its scale. If the scale of the result
* becomes negative, then its precision is increased such that the scale is
* zero.
- * <p>
- * Note, that {@code movePointLeft(0)} returns a result which is
- * mathematically equivalent, but which has {@code scale >= 0}.
*
- * @param n
- * number of placed the decimal point has to be moved.
- * @return {@code this * 10^(-n}).
+ * <p>Note, that {@code movePointLeft(0)} returns a result which is
+ * mathematically equivalent, but which has {@code scale >= 0}.
*/
public BigDecimal movePointLeft(int n) {
return movePoint(scale + (long)n);
@@ -2031,33 +1983,25 @@
* Returns a new {@code BigDecimal} instance where the decimal point has
* been moved {@code n} places to the right. If {@code n < 0} then the
* decimal point is moved {@code -n} places to the left.
- * <p>
- * The result is obtained by changing its scale. If the scale of the result
+ *
+ * <p>The result is obtained by changing its scale. If the scale of the result
* becomes negative, then its precision is increased such that the scale is
* zero.
- * <p>
- * Note, that {@code movePointRight(0)} returns a result which is
- * mathematically equivalent, but which has scale >= 0.
*
- * @param n
- * number of placed the decimal point has to be moved.
- * @return {@code this * 10^n}.
+ * <p>Note, that {@code movePointRight(0)} returns a result which is
+ * mathematically equivalent, but which has scale >= 0.
*/
public BigDecimal movePointRight(int n) {
return movePoint(scale - (long)n);
}
/**
- * Returns a new {@code BigDecimal} whose value is {@code this} 10^{@code n}.
+ * Returns a new {@code BigDecimal} whose value is {@code this * 10<sup>n</sup>}.
* The scale of the result is {@code this.scale()} - {@code n}.
* The precision of the result is the precision of {@code this}.
- * <p>
- * This method has the same effect as {@link #movePointRight}, except that
- * the precision is not changed.
*
- * @param n
- * number of places the decimal point has to be moved.
- * @return {@code this * 10^n}
+ * <p>This method has the same effect as {@link #movePointRight}, except that
+ * the precision is not changed.
*/
public BigDecimal scaleByPowerOfTen(int n) {
long newScale = scale - (long)n;
@@ -2170,12 +2114,8 @@
* Returns {@code true} if {@code x} is a {@code BigDecimal} instance and if
* this instance is equal to this big decimal. Two big decimals are equal if
* their unscaled value and their scale is equal. For example, 1.0
- * (10*10^(-1)) is not equal to 1.00 (100*10^(-2)). Similarly, zero
+ * (10*10<sup>-1</sup>) is not equal to 1.00 (100*10<sup>-2</sup>). Similarly, zero
* instances are not equal if their scale differs.
- *
- * @param x
- * object to be compared with {@code this}.
- * @return true if {@code x} is a {@code BigDecimal} and {@code this == x}.
*/
@Override
public boolean equals(Object x) {
@@ -2187,8 +2127,6 @@
return x1.scale == scale
&& (bitLength < 64 ? (x1.smallValue == smallValue)
: intVal.equals(x1.intVal));
-
-
}
return false;
}
@@ -2461,9 +2399,7 @@
/**
* Returns this {@code BigDecimal} as an long value. Any fractional part is
* discarded. If the integral part of {@code this} is too big to be
- * represented as an long, then {@code this} % 2^64 is returned.
- *
- * @return this {@code BigDecimal} as a long value.
+ * represented as an long, then {@code this % 2<sup>64</sup>} is returned.
*/
@Override
public long longValue() {
@@ -2472,16 +2408,14 @@
* 10^(-scale). If the scale is positive and very large the long value
* could be zero.
*/
- return ((scale <= -64) || (scale > approxPrecision()) ? 0L
- : toBigInteger().longValue());
+ return ((scale <= -64) || (scale > approxPrecision()) ? 0L : toBigInteger().longValue());
}
/**
* Returns this {@code BigDecimal} as a long value if it has no fractional
- * part and if its value fits to the int range ([-2^{63}..2^{63}-1]). If
+ * part and if its value fits to the int range ([-2<sup>63</sup>..2<sup>63</sup>-1]). If
* these conditions are not met, an {@code ArithmeticException} is thrown.
*
- * @return this {@code BigDecimal} as a long value.
* @throws ArithmeticException
* if rounding is necessary or the number doesn't fit in a long.
*/
@@ -2492,9 +2426,7 @@
/**
* Returns this {@code BigDecimal} as an int value. Any fractional part is
* discarded. If the integral part of {@code this} is too big to be
- * represented as an int, then {@code this} % 2^32 is returned.
- *
- * @return this {@code BigDecimal} as a int value.
+ * represented as an int, then {@code this % 2<sup>32</sup>} is returned.
*/
@Override
public int intValue() {
@@ -2503,36 +2435,31 @@
* 10^(-scale). If the scale is positive and very large the long value
* could be zero.
*/
- return ((scale <= -32) || (scale > approxPrecision())
- ? 0
- : toBigInteger().intValue());
+ return ((scale <= -32) || (scale > approxPrecision()) ? 0 : toBigInteger().intValue());
}
/**
* Returns this {@code BigDecimal} as a int value if it has no fractional
- * part and if its value fits to the int range ([-2^{31}..2^{31}-1]). If
+ * part and if its value fits to the int range ([-2<sup>31</sup>..2<sup>31</sup>-1]). If
* these conditions are not met, an {@code ArithmeticException} is thrown.
*
- * @return this {@code BigDecimal} as a int value.
* @throws ArithmeticException
- * if rounding is necessary or the number doesn't fit in a int.
+ * if rounding is necessary or the number doesn't fit in an int.
*/
public int intValueExact() {
- return (int)valueExact(32);
+ return (int) valueExact(32);
}
/**
* Returns this {@code BigDecimal} as a short value if it has no fractional
- * part and if its value fits to the short range ([-2^{15}..2^{15}-1]). If
+ * part and if its value fits to the short range ([-2<sup>15</sup>..2<sup>15</sup>-1]). If
* these conditions are not met, an {@code ArithmeticException} is thrown.
*
- * @return this {@code BigDecimal} as a short value.
* @throws ArithmeticException
- * if rounding is necessary of the number doesn't fit in a
- * short.
+ * if rounding is necessary of the number doesn't fit in a short.
*/
public short shortValueExact() {
- return (short)valueExact(16);
+ return (short) valueExact(16);
}
/**
@@ -2540,12 +2467,11 @@
* part and if its value fits to the byte range ([-128..127]). If these
* conditions are not met, an {@code ArithmeticException} is thrown.
*
- * @return this {@code BigDecimal} as a byte value.
* @throws ArithmeticException
* if rounding is necessary or the number doesn't fit in a byte.
*/
public byte byteValueExact() {
- return (byte)valueExact(8);
+ return (byte) valueExact(8);
}
/**
@@ -2559,7 +2485,7 @@
* <p>
* For example, if the instance {@code x1 = new BigDecimal("0.1")} cannot be
* represented exactly as a float, and thus {@code x1.equals(new
- * BigDecimal(x1.folatValue())} returns {@code false} for this case.
+ * BigDecimal(x1.floatValue())} returns {@code false} for this case.
* <p>
* Similarly, if the instance {@code new BigDecimal(16777217)} is converted
* to a float, the result is {@code 1.6777216E}7.
@@ -2708,13 +2634,12 @@
* Returns the unit in the last place (ULP) of this {@code BigDecimal}
* instance. An ULP is the distance to the nearest big decimal with the same
* precision.
- * <p>
- * The amount of a rounding error in the evaluation of a floating-point
+ *
+ * <p>The amount of a rounding error in the evaluation of a floating-point
* operation is often expressed in ULPs. An error of 1 ULP is often seen as
* a tolerable error.
- * <p>
- * For class {@code BigDecimal}, the ULP of a number is simply 10^(-scale).
- * <p>
+ *
+ * <p>For class {@code BigDecimal}, the ULP of a number is simply 10<sup>-scale</sup>.
* For example, {@code new BigDecimal(0.1).ulp()} returns {@code 1E-55}.
*
* @return unit in the last place (ULP) of this {@code BigDecimal} instance.
diff --git a/luni/src/main/java/java/math/BigInteger.java b/luni/src/main/java/java/math/BigInteger.java
index e58bfd5..90bf0f6 100644
--- a/luni/src/main/java/java/math/BigInteger.java
+++ b/luni/src/main/java/java/math/BigInteger.java
@@ -24,7 +24,7 @@
import java.util.Random;
/**
- * An immutable signed integer of arbitrary magnitude.
+ * An immutable arbitrary-precision signed integer.
*
* <h3>Fast Cryptography</h3>
* This implementation is efficient for operations traditionally used in
diff --git a/luni/src/main/java/java/text/SimpleDateFormat.java b/luni/src/main/java/java/text/SimpleDateFormat.java
index f682c0b..760d6a0 100644
--- a/luni/src/main/java/java/text/SimpleDateFormat.java
+++ b/luni/src/main/java/java/text/SimpleDateFormat.java
@@ -79,10 +79,10 @@
* <tr> <td>{@code m}</td> <td>minute in hour</td> <td>(Number)</td> <td>30</td> </tr>
* <tr> <td>{@code s}</td> <td>second in minute</td> <td>(Number)</td> <td>55</td> </tr>
* <tr> <td>{@code w}</td> <td>week in year</td> <td>(Number)</td> <td>27</td> </tr>
- * <tr> <td>{@code y}</td> <td>year</td> <td>(Number)</td> <td>2010</td> </tr>
- * <tr> <td>{@code z}</td> <td>time zone</td> <td>(Timezone)</td> <td>Pacific Standard Time</td> </tr>
- * <tr> <td>{@code '}</td> <td>escape for text</td> <td>(Delimiter)</td> <td>'Date='</td> </tr>
- * <tr> <td>{@code ''}</td> <td>single quote</td> <td>(Literal)</td> <td>'o''clock'</td> </tr>
+ * <tr> <td>{@code y}</td> <td>year</td> <td>(Number)</td> <td>{@code yy}:10 {@code y}/{@code yyy}/{@code yyyy}:2010</td> </tr>
+ * <tr> <td>{@code z}</td> <td>time zone</td> <td>(Timezone)</td> <td>{@code z}/{@code zz}/{@code zzz}:PST {@code zzzz}:Pacific Standard Time</td> </tr>
+ * <tr> <td>{@code '}</td> <td>escape for text</td> <td>(Delimiter)</td> <td>{@code 'Date='}:Date=</td> </tr>
+ * <tr> <td>{@code ''}</td> <td>single quote</td> <td>(Literal)</td> <td>{@code 'o''clock'}:o'clock</td> </tr>
* </table>
*
* <p>The number of consecutive copies (the "count") of a pattern character further influences
@@ -108,8 +108,12 @@
* </ul>
*
* <p>The two pattern characters {@code L} and {@code c} are ICU-compatible extensions, not
- * available in the RI. These are necessary for correct localization in languages such as Russian
- * that distinguish between, say, "June" and "June 2010".
+ * available in the RI or in Android before Android 2.3 "Gingerbread" (API level 9). These
+ * extensions are necessary for correct localization in languages such as Russian
+ * that make a grammatical distinction between, say, the word "June" in the sentence "June" and
+ * in the sentence "June 10th"; the former is the stand-alone form, the latter the regular
+ * form (because the usual case is to format a complete date). The relationship between {@code E}
+ * and {@code c} is equivalent, but for weekday names.
*
* <p>When numeric fields are adjacent directly, with no intervening delimiter
* characters, they constitute a run of adjacent numeric fields. Such runs are
diff --git a/luni/src/main/java/java/util/Formatter.java b/luni/src/main/java/java/util/Formatter.java
index 021da08..caf5c49 100644
--- a/luni/src/main/java/java/util/Formatter.java
+++ b/luni/src/main/java/java/util/Formatter.java
@@ -321,6 +321,7 @@
* <br>
* Calendar, Date, and Long (representing milliseconds past the epoch) are all acceptable
* as date/time arguments. Any other type is an error. The epoch is 1970-01-01 00:00:00 UTC.
+ * <font color="red">Use {@link java.text.SimpleDateFormat} instead.</font>
* </TD>
* </tr>
* <tr>
@@ -391,14 +392,14 @@
* </tr>
* <tr>
* <td width="5%">{@code tH}</td>
- * <td width="25%">24-hour hour of day (00-23).</td>
+ * <td width="25%">2-digit 24-hour hour of day (00-23).</td>
* <td width="30%">{@code format("%tH", cal);}</td>
* <td width="30%">{@code 16}</td>
* </tr>
* <tr>
* <td width="5%">{@code tI}</td>
- * <td width="25%">12-hour hour of day (01-12).</td>
- * <td width="30%">{@code format("%tH", cal);}</td>
+ * <td width="25%">2-digit 12-hour hour of day (01-12).</td>
+ * <td width="30%">{@code format("%tI", cal);}</td>
* <td width="30%">{@code 04}</td>
* </tr>
* <tr>
@@ -410,13 +411,13 @@
* <tr>
* <td width="5%">{@code tk}</td>
* <td width="25%">24-hour hour of day (0-23).</td>
- * <td width="30%">{@code format("%tH", cal);}</td>
+ * <td width="30%">{@code format("%tk", cal);}</td>
* <td width="30%">{@code 16}</td>
* </tr>
* <tr>
* <td width="5%">{@code tl}</td>
* <td width="25%">12-hour hour of day (1-12).</td>
- * <td width="30%">{@code format("%tH", cal);}</td>
+ * <td width="30%">{@code format("%tl", cal);}</td>
* <td width="30%">{@code 4}</td>
* </tr>
* <tr>