United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4366946 Spec for java.net.JarURLConnection is inconsistent with implementation
JDK-4366946 : Spec for java.net.JarURLConnection is inconsistent with implementation

Details
Type:
Bug
Submit Date:
2000-08-30
Status:
Closed
Updated Date:
2004-09-01
Project Name:
JDK
Resolved Date:
2003-10-10
Component:
core-libs
OS:
solaris_2.6,generic
Sub-Component:
java.net
CPU:
sparc,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.2.0,1.4.0,5.0
Fixed Versions:
5.0 (tiger)

Related Reports

Sub Tasks

Description

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
----------------------------------------------

======================================================================

                                    

Comments
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
                                     
2002-04-18
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b24

VERIFIED IN:
tiger-rc


                                     
2004-09-13



Hardware and Software, Engineered to Work Together