JDK-4366946 : Spec for java.net.JarURLConnection is inconsistent with implementation
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.2.0,1.4.0,5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_2.6
  • CPU: generic,sparc
  • Submitted: 2000-08-30
  • Updated: 2017-05-16
  • Resolved: 2003-10-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
5.0 tigerFixed

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("Trying modify jarEntry");
                System.out.println("old comment: " + entry.getComment());
                System.out.println("new comment: " + entry.getComment());
                System.out.println("No exception thrown, jarEntry modified");
                passed = false;
            } catch (Exception e) {

            try {
                System.out.println("Trying modify manifest");
                System.out.println("getMainAttributes.isEmpty(): " 
                    + manifest.getMainAttributes().isEmpty());

                System.out.println("after clear(): getMainAttributes.isEmpty(): " 
                    + manifest.getMainAttributes().isEmpty());
                System.out.println("No exception thrown, manifest modified");
                passed = false;
            } catch (Exception e) {

            if (passed) 
                System.out.println("Test passed");
                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


CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b24 VERIFIED IN: tiger-rc

EVALUATION Will consider for 1.4.1. Probably the implementation should change to obey the spec. ###@###.### 2001-10-10 Actually, it doesnt make sense to throw an UnsupportedOperationException because there are no methods on JarFile that could conceivably modify the object. Therefore, it makes more sense to remove the statement from the spec. Will defer this to mantis. ###@###.### 2002-04-18 Defer to tiger. ###@###.### 2002-10-30