Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7002855

reading a .class resource from jar input stream does not work with jdk7 b116

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 7
    • 7
    • core-libs
    • None

      The following code reads and prints as expected with jdk6 1.6.0_22. But, this prints all zeros with jdk7 b119. This was run on Ubuntu 10.04.

      File: Test.java

      import java.io.*;

      public class Test {
        public static void main(String[] args) throws Exception {
            InputStream is = Test.class.getResourceAsStream("Test.class");
            System.out.println(is);
            byte[] header = new byte[8];
            is.read(header);
            for (byte b : header) {
                  System.out.println(b);
            }
            int minor = (header[4] << 8) | header[5];
            int major = (header[6] << 8) | header[7];
            System.out.println("minor " + minor);
            System.out.println("major " + major);
        }
      }

      Steps to reproduce:

      1) java Test.java
      2) jar cvf test.jar Test.class
      3) java -cp test.jar Test

      With jdk7, I got the following result:


      $ ~/bin/jdk1.7.0/bin/java -cp test.jar Test
      sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@117a8bd
      -54
      0
      0
      0
      0
      0
      0
      0
      minor 0
      major 0

      With jdk6, I get the following result:

      $ java -cp test.jar Test
      sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@1690726
      -54
      -2
      -70
      -66
      0
      0
      0
      50
      minor 0
      major 50
      If a println is added,

          System.out.println(is.read(header));

      instead of

          is.read(header)

      then the test works as expected even with jdk7 b119.

      This does suggest it *may* be a JVM issue.

            sherman Xueming Shen
            sundar Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: