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

(diag) Better diagnostics for zipfile w/ sources

XMLWordPrintable

    • b23
    • generic, x86
    • generic, solaris_2.5.1, windows_nt, windows_2000
    • Verified

      I made a zip file which contained .java files rather than .class files; this is not something that one is supposed to do. When I compiled a class against this zip file, I got the message:

      I/O exception
      1 error

      It seems to me that the compiler should give a more meaningful error message when encountering a confusing zip file.

      Here is a session which has enough information to reproduce the bug:

      219%> m one/two/*.java one/three/*.java
      ::::::::::::::
      one/two/Two.java
      ::::::::::::::
      package one.two;
       
      public class Two {
              public int x = 20;
      }
      ::::::::::::::
      one/three/Three.java
      ::::::::::::::
      package one.three;
       
      public class Three {
              public int y = 40;
      }
      220%> zip -0 out.zip one/two/*.java one/three/*.java
        adding: one/two/Two.java (stored 0%)
        adding: one/three/Three.java (stored 0%)
      invisible:~/bugtest/bold/ziptest 221%> m frog.java
      import one.two.*;
       
      public class frog {
              frog() {
                      int z = new Two().x;
                      System.out.println(z);
              }
              public static void main(String[] args) {
                      new frog();
              }
      }
       
      222%> javac frog.java -classpath one.zip:<regularClassPath>
      I/O exception
      1 error

      ---

      In JDK 1.3 and JDK 1.2, a spurious error is generated when compiling source
      files from a .jar file. Undoubtedly, the problem with .zip files and .jar
      files is related, if not identical. See 4232697.

      william.maddox@Eng 2000-02-01


      Name: tb29552 Date: 12/21/2001


      /*
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)

      I am doing a compilation for which some of the source files are archived in a
      jar file. I compile with "javac -sourcepath files.jar". If none of the files
      contain public classes, compilation succeeds. Othewise, I get an error message
      complaining that the name of the file is wrong.

      (1) Create two files. One is "foo.java":
      */
      public class foo {
        public static void main (String[] args) {
          new bar();
        }
      }

      /*
      the other is "bar.java":
      */

      public class bar {
      }


      (2) Compile with javac, and all is well:

      javac foo.java


      (3) Put bar.java into a jar file and delete bar.java.

      jar -cf bar.jar bar.java

      (4) Delete all .class files

      (5) and try compiling again, this time using a sourcepath option.

      javac -sourcepath bar.jar foo.java

      This error message appears:

      bar.jar(bar.java):1: class bar is public, should be declared in a file named
      bar.java
      (source unavailable)
      1 error
      (Review ID: 136989)
      ======================================================================

            jjg Jonathan Gibbons
            tturnidgsunw Todd Turnidge (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: