Bug 40776 - a problem compiling a Java 5 project with generics
Summary: a problem compiling a Java 5 project with generics
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.5
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: 1.7.1
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-17 09:31 UTC by Chavdar Botev
Modified: 2008-07-27 11:33 UTC (History)
0 users



Attachments
Sample project for reproducing the problem (1.83 KB, application/zip)
2006-10-17 09:32 UTC, Chavdar Botev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chavdar Botev 2006-10-17 09:31:10 UTC
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
Comment 1 Chavdar Botev 2006-10-17 09:32:08 UTC
Created attachment 19017 [details]
Sample project for reproducing the problem
Comment 2 Chavdar Botev 2006-10-17 09:33:46 UTC
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
Comment 3 Peter Reilly 2006-10-17 09:35:21 UTC
Upping the severity level.
Comment 4 Jan Mat 2006-10-18 04:13:17 UTC
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>
Comment 5 Jan Mat 2006-10-18 05:01:05 UTC
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. :-(
Comment 6 Peter Portante 2007-07-10 13:07:29 UTC
I have also verified that this occurs under 1.6.4. -peter
Comment 7 Peter Reilly 2007-07-20 10:19:06 UTC
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.
Comment 8 CM 2008-07-27 11:33:49 UTC
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.