Plug a resource leak with "finally" and make Object.getClass' return type match Java 6.
Change-Id: Ia8ae90634bfb3680c8e82e4e4cf7f7459263c3d3
diff --git a/luni-kernel/src/main/java/java/lang/Class.java b/luni-kernel/src/main/java/java/lang/Class.java
index e999c92..35e47bc 100644
--- a/luni-kernel/src/main/java/java/lang/Class.java
+++ b/luni-kernel/src/main/java/java/lang/Class.java
@@ -117,8 +117,6 @@
* <li>{@code [Ljava/lang/String;} representing the {@code String[]} type</li>
* <li>{@code [[[C} representing the {@code char[][][]} type (three dimensions!)</li>
* </ul>
- *
- * @since Android 1.0
*/
public final class Class<T> implements Serializable, AnnotatedElement, GenericDeclaration, Type {
diff --git a/luni-kernel/src/main/java/java/lang/Object.java b/luni-kernel/src/main/java/java/lang/Object.java
index 4fef609..d9613f8 100644
--- a/luni-kernel/src/main/java/java/lang/Object.java
+++ b/luni-kernel/src/main/java/java/lang/Object.java
@@ -148,10 +148,10 @@
}
/**
- * Returns the unique instance of {@link Class} which represents this
+ * Returns the unique instance of {@link Class} that represents this
* object's class. Note that {@code getClass()} is a special case in that it
* actually returns {@code Class<? extends Foo>} where {@code Foo} is the
- * erasure of the type of expression {@code getClass()} was called upon.
+ * erasure of the type of the expression {@code getClass()} was called upon.
* <p>
* As an example, the following code actually compiles, although one might
* think it shouldn't:
@@ -162,9 +162,8 @@
* </pre>
*
* @return this object's {@code Class} instance.
- * @since Android 1.0
*/
- public final native Class<? extends Object> getClass();
+ public final native Class<?> getClass();
/**
* Returns an integer hash code for this object. By contract, any two
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
index 493b768..eb678f8 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
@@ -150,24 +150,32 @@
jar = AccessController
.doPrivileged(new PrivilegedAction<JarFile>() {
public JarFile run() {
+ FileOutputStream fos = null;
+ JarFile result = null;
try {
- File tempJar = File.createTempFile(
- "hyjar_", ".tmp", null);
+ File tempJar = File.createTempFile("hyjar_", ".tmp", null);
tempJar.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(
- tempJar);
+ fos = new FileOutputStream(tempJar);
byte[] buf = new byte[4096];
int nbytes = 0;
while ((nbytes = is.read(buf)) > -1) {
fos.write(buf, 0, nbytes);
}
fos.close();
- return new JarFile(tempJar, true,
- ZipFile.OPEN_READ
- | ZipFile.OPEN_DELETE);
+ result = new JarFile(tempJar, true,
+ ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
} catch (IOException e) {
return null;
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException ex) {
+ result = null;
+ }
+ }
}
+ return result;
}
});
} finally {