-
Bug
-
Resolution: Fixed
-
P4
-
1.2.0, 1.4.0, 5.0
-
tiger
-
generic, sparc
-
generic, solaris_2.6
-
Verified
Name: dfR10049 Date: 08/30/2000
Javadoc states that java.net.JarURLConnection.getJarFile():
* The returned object is
* not modifiable, and will throw UnsupportedOperationException
* if the caller attempts to modify it.
But there is no way to modify JarFile object in JDK. So these words
are unnecessary and can be removed from spec.
Javadoc states the same about getJarEntry() and getManifest() methods.
But no exceptions are thrown if we try to modify returned objects.
This is the test demonstrated the bug:
-------------------- Test.java ------------------------
import java.net.*;
import java.io.*;
import java.util.jar.*;
public class Test {
public static void main (String args[]){
URL jarURL = null;
String spec = "http://java.sun.com/products/javawebstart/lib/draw.jar";
boolean passed = true;
try {
jarURL = new URL("jar:" + spec + "!/Draw.class");
System.out.println("url: " + jarURL);
JarURLConnection con = (JarURLConnection)jarURL.openConnection();
JarFile jar = con.getJarFile();
JarEntry entry = con.getJarEntry();
Manifest manifest = con.getManifest();
System.out.println("jar name: " + jar.getName());
System.out.println("entry name: " + entry.getName());
System.out.println("manifest: " + manifest);
try {
System.out.println("--------------------------------------");
System.out.println("Trying modify jarEntry");
System.out.println("old comment: " + entry.getComment());
entry.setComment("COMMENTS");
System.out.println("new comment: " + entry.getComment());
System.out.println("No exception thrown, jarEntry modified");
passed = false;
} catch (Exception e) {
}
try {
System.out.println("--------------------------------------");
System.out.println("Trying modify manifest");
System.out.println("getMainAttributes.isEmpty(): "
+ manifest.getMainAttributes().isEmpty());
manifest.clear();
System.out.println("after clear(): getMainAttributes.isEmpty(): "
+ manifest.getMainAttributes().isEmpty());
System.out.println("No exception thrown, manifest modified");
passed = false;
} catch (Exception e) {
}
System.out.println("--------------------------------------");
if (passed)
System.out.println("Test passed");
else
System.out.println("Test failed");
} catch (Exception e) {
System.out.println(" " + e);
}
}
}
-------- output from the text ----------------
#> java -Dhttp.proxyHost=guard -Dhttp.proxyPort=3128 Test
url: jar:http://java.sun.com/products/javawebstart/lib/draw.jar!/Draw.class
jar name: /var/tmp/jar_cache20845.tmp
entry name: Draw.class
manifest: java.util.jar.Manifest@ee76f65b
--------------------------------------
Trying modify jarEntry
old comment: null
new comment: COMMENTS
No exception thrown, jarEntry modified
--------------------------------------
Trying modify manifest
getMainAttributes.isEmpty(): false
after clear(): getMainAttributes.isEmpty(): true
No exception thrown, manifest modified
--------------------------------------
Test failed
----------------------------------------------
======================================================================