Hi! I've come accross the following problem trying to compile Java 5 classes with generics using Ant 1.6.5. I've attached the archived project with sample Java classes and a build.xml file. A clean build of the above project works just fine and compiles without a problem. If after that, I touch the Test3.java file the build fails with the following error: [javac] C:\src\appforge\test\src\test\Test3.java:5: incompatible types [javac] found : test.Base [javac] required: test.Sub [javac] public Sub p() {return this.getV();} [javac] ^ [javac] 1 error Initially, I thought that this was a problem with the Java compiler. After touching Test3.java, I tried running javac manually: javac -sourcepath src -d bin -g -source 1.5 -target 1.5 src\test\*.java It turned out that with the above command-line the project compiled OK. The project also compiles without a problem in Eclipse 3.2.1. Upon further experimentation, if I uncomment the method in Test2.java fixes the problem. Touching Test3.java does not break the build. I've been able to reproduce the problem both on Windows XP with JDK 1.5.0_08 and on RedHat EL4 with 1.5.0_07. Thanks, Chavdar
Created attachment 19017 [details] Sample project for reproducing the problem
There is also a thread about this issue on the user mailing list at http://marc.theaimsgroup.com/?l=ant-user&m=116110133201615&w=2
Upping the severity level.
Ok, could also verify that with the given sample project. I changed the buildfile, so a single Ant run would produce the error: <project name="Test" default="build"> <presetdef name="compile"> <javac srcdir="src" destdir="bin" target="1.5" source="1.5" debug="true" listfiles="true"> </javac> </presetdef> <target name="build"> <mkdir dir="bin"/> <compile/> <delete><fileset dir="bin/test" includes="Test3*.class"/></delete> <compile/> </target> </project>
Also tested with Ant 1.7.0beta2 (September 17 2006) on Java 1.6 (1.6.0-rc-b102) on WinXP-SP2. Error does occur. :-(
I have also verified that this occurs under 1.6.4. -peter
I have added an new attribute to the javac task - includeDestClasses. This is by default set to true - in which case the javac task includes the destination directory in the classpath parameter given to javac command (default behaviour), if set to false, this will not happen. the build file: <project name="Test" default="build"> <presetdef name="compile"> <javac srcdir="src" destdir="bin" target="1.5" source="1.5" debug="true" includeDestClasses="false" listfiles="true"> </javac> </presetdef> <target name="build"> <mkdir dir="bin"/> <compile/> <delete><fileset dir="bin/test" includes="Test3*.class"/></delete> <compile/> </target> </project> now works.
I think there is other "edge cases" for that which are solved by this bug fix: 1- Interface A has a method x with "void" return type. 2- Class B uses an instance that implements interface A, and calls the void method x. from -1. 3- Interface A is refactored and method x to return an Object (not void anymore). 4- Class B is not modified and still compiles: it just call x still with no concern on the returned value. 5- Using javac in Ant, Class B is untouched and not recompiled. At runtime, B fails calling the method x. Forcing recompile of B fixes the runtime problem. Using 1.7.1 with the new attribute includeDestClasses="false" also fixes the problem.