6295519: javac throws ZipException when you have invalid files in classpath
The root cause is that Javac assumes all files in the classpath are jar files or zip files, and tries to open them using
java.util.zip
API, which will fail if the classpath contains other types of files, such as *.class, *.so, etc. From the bug description, it was a regression from JDK 1.4.0_01, and exists from 1.4.0_02 to 1.5.0_06. Note that it is NOT a Java bug, but a Javac bug. I did a quick test on my 5.0_06 Javac, and was able to reproduce the same error:error: error reading /appserver/lib/LauncherBootstrap.class;It's pretty common to fall victim to this bug. For example, suppose you wan to include all files under /appserver/lib in Javac classpath, so you would write compile target like:
java.util.zip.ZipException: error in opening zip file
1 error
<target name="compile">Your intention is to include all *.jar and *.zip files under /appserver/lib directory. But this directory may also include *.so files and even *.class files, which will cause this bug. To work around this bug, you will need to be more specific:
<javac srcdir="src" destdir="build/classes" includes="**/*.java">
<classpath>
<fileset dir="/appserver/lib" includes="*"/>
</classpath>
</javac>
</target>
includes="*.jar, *.zip"
.