A Noteworthy Javac Bug Fix in JDK 5.0 Update 7

JDK 5.0 update 7 (JDK 1.5.0_07) was released last week. As I skim through the release note and bug fixes, I noticed this Javac bug:

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;
java.util.zip.ZipException: error in opening zip file
1 error
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:
<target name="compile">
<javac srcdir="src" destdir="build/classes" includes="**/*.java">
<classpath>
<fileset dir="/appserver/lib" includes="*"/>
</classpath>
</javac>
</target>
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: includes="*.jar, *.zip".

Followers

Pageviews Last 7 Days