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">
<fileset dir="/appserver/lib" includes="*"/>
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".


Anna said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Denisa Cretu said...

I just want to say thanks for your wonderful post, it is contain a lot of knowledge and information that i needed right now. Thanks!
juegosfrivol , friv2planet , friv400game

For You said...

This is a great web site, Good sparkling user interface and, very informative blogs. I have found it enormously useful. Thanks you very good !
Kizi 9
Kizi 8
Kizi 7