You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Sergey Bondarenko <en...@gmail.com> on 2008/10/30 19:22:47 UTC

javac task problem in Java 6

Hi dear Ant developers!


I think I found a bug in Ant javac task, (or maybe in Java compiler).
I need you help to check if it is true.

Javac task behaves differently in Java 6 and Java 5.
For some reason it works properly in Java 5 on the same project structure,
but fails in Java 6.

Imagine situation when you have 3 classes with dependencies between them:
A -> B -> C

Then you compile C.java and pack into c.jar
Then you compile B.java, using c.jar in classpath, and pack it into b.jar

Then you compile A.java, using b.jar.

It works properly in Java 5, but fails in Java 6: compiler can not resolve
dependency B->C (though you compile only A class).


I created simple test case, so could you please look at it and try to find
out the cause of the problem?
http://download.cl1p.net/javac_bug/?FILE=17647
There are two bat-files in archive: works.bat and fails.bat. The only
difference between them is JDK version.

I tried on Ant 1.7.1 and 1.6.5, using jdk1.6.0_10 and jdk1.5.0_16.
The result is stable: compilation works on JDK 5, and fails on JDK 6.

Any help is appreciated.
Thanks!


Regards,
Sergey Bondarenko.

Re: javac task problem in Java 6

Posted by Mark Salter <ma...@talktalk.net>.
Sergey Bondarenko wrote:

> I created simple test case, so could you please look at it and try to find
> out the cause of the problem?
> http://download.cl1p.net/javac_bug/?FILE=17647
> There are two bat-files in archive: works.bat and fails.bat. The only
> difference between them is JDK version.
I don't have the same versions of the jdk as you (jdk1.5.0_06 &
jdk1.6.0_03 here), but here both these versions 'work'.  There could of
course be changes in your versions to cause the failure...

...May I suggest you invoke ant with -verbose -diagnostics, so you may
check if there are any differences between the two invocations in your
environment at all?  Comparing the full output from each jdk may provide
some clues.

-- 
Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: javac task problem in Java 6

Posted by Stefan Bodewig <bo...@apache.org>.
On Sat, 1 Nov 2008, Sergey Bondarenko <en...@gmail.com> wrote:

> Any new regarding this issue?

IMHO you are simply not sending your question to the set of people
that could answer them.  Based on your description the javac compilers
behave differently, but Ant doesn't.  I don't see how the Ant
developers might help you.

If you really think this is a bug in Ant, then please provide more
information about your setup (how does A depend on B and B depend on
C?).  A self contained build file would be best.

It would be good if you verified that running javac from the command
line shows a different behavior than Ant.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: javac task problem in Java 6

Posted by Sergey Bondarenko <en...@gmail.com>.
Any new regarding this issue?

Thanks!

Sergey.

2008/10/30 Sergey Bondarenko <en...@gmail.com>

> Hi dear Ant developers!
>
>
> I think I found a bug in Ant javac task, (or maybe in Java compiler).
> I need you help to check if it is true.
>
> Javac task behaves differently in Java 6 and Java 5.
> For some reason it works properly in Java 5 on the same project structure,
> but fails in Java 6.
>
> Imagine situation when you have 3 classes with dependencies between them:
> A -> B -> C
>
> Then you compile C.java and pack into c.jar
> Then you compile B.java, using c.jar in classpath, and pack it into b.jar
>
> Then you compile A.java, using b.jar.
>
> It works properly in Java 5, but fails in Java 6: compiler can not resolve
> dependency B->C (though you compile only A class).
>
>
> I created simple test case, so could you please look at it and try to find
> out the cause of the problem?
> http://download.cl1p.net/javac_bug/?FILE=17647
> There are two bat-files in archive: works.bat and fails.bat. The only
> difference between them is JDK version.
>
> I tried on Ant 1.7.1 and 1.6.5, using jdk1.6.0_10 and jdk1.5.0_16.
> The result is stable: compilation works on JDK 5, and fails on JDK 6.
>
> Any help is appreciated.
> Thanks!
>
>
> Regards,
> Sergey Bondarenko.
>

Re: javac task problem in Java 6

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 5 Nov 2008, Sergey Bondarenko <en...@gmail.com> wrote:

> Hi Stefan!
> 
> I followed your advice and set sourcepath to "".
> 
> Compilation by javac works properly in JDK 5 and 6:
> javac -sourcepath "" -classpath b.jar A.java
> 
> Compilation by ant task works properly in JDK 5, but does not work
> in JDK 6

This is not what Ant does.  Compilation looks more like

javac -d . -sourcepath . -classpath b.jar A.java

without setting sourcepath (Ant uses srcdir as sourcepath in that
case) and

javac -d . -classpath b.jar A.java

with sourcepath="".

The problem seems to be that destdir==srcdir in your case.  If I
create a directory d and set destdir="d" then only A gets compiled (on
Java4 as well as Java5).  It seems as if Java6's javac searches the
destination directory for sources as well.

> I understand that Ant compiles classes using tools.jar, so there is
> no straight way to write the same command line.

If you set fork="true" it will use the command line, but the
in-process execution really should look the same.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: javac task problem in Java 6

Posted by Sergey Bondarenko <en...@gmail.com>.
Hi Stefan!

I followed your advice and set sourcepath to "".

Compilation by javac works properly in JDK 5 and 6:
javac -sourcepath "" -classpath b.jar A.java

Compilation by ant task works properly in JDK 5, but does not work in JDK 6:
<project default="compile">
    <target name="compile">
        <javac sourcepath="" srcdir = "." destdir="." includes="A.java"
excludes="B.java">
            <classpath>
                <pathelement path="b.jar"/>
            </classpath>
        </javac>
    </target>
</project>


So there is a problem in the way Ant works with javac.
I understand that Ant compiles classes using tools.jar, so there is no
straight way to write the same command line.
But since JDK javac compiler works properly in both JDK, I suppose that
something is wrong in Ant's javac task.
Is it correct?


BTW, did you try to compile classes from javac_issue.zip that I had sent
earlier?


Regards,
Sergey Bondarenko.


2008/11/5 Stefan Bodewig <bo...@apache.org>

> On Tue, 4 Nov 2008, Sergey Bondarenko <en...@gmail.com> wrote:
>
> > javac -sourcepath A.java -classpath b.jar A.java
> > It works properly in both JDK 5 and 6.
>
> This is not what Ant does (and why I pointed you at sourcepath="" in
> order to get something like that.
>
> > But Ant's javac task with "includes" and "excludes" does not work
> > with JDK 6.
>
> See my response.
>
> > So I am not sure that problem is in javac compiler. It looks like
> > there is a problem in javac Ant task.  Could anybody please check
> > it?  Is there any way to look at exact javac invocation string that
> > is produced for the build script?
>
> Run Ant with -verbose.
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

Re: javac task problem in Java 6

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 4 Nov 2008, Sergey Bondarenko <en...@gmail.com> wrote:

> javac -sourcepath A.java -classpath b.jar A.java
> It works properly in both JDK 5 and 6.

This is not what Ant does (and why I pointed you at sourcepath="" in
order to get something like that.

> But Ant's javac task with "includes" and "excludes" does not work
> with JDK 6.

See my response.

> So I am not sure that problem is in javac compiler. It looks like
> there is a problem in javac Ant task.  Could anybody please check
> it?  Is there any way to look at exact javac invocation string that
> is produced for the build script?

Run Ant with -verbose.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: javac task problem in Java 6

Posted by Sergey Bondarenko <en...@gmail.com>.
Well, I tried javac:

javac -sourcepath A.java -classpath b.jar A.java
It works properly in both JDK 5 and 6.

But Ant's javac task with "includes" and "excludes" does not work with JDK
6.

So I am not sure that problem is in javac compiler. It looks like there is a
problem in javac Ant task.
Could anybody please check it?
Is there any way to look at exact javac invocation string that is produced
for the build script?

Regards,
Sergey Bondarenko.


2008/11/4 Jess Holle <je...@ptc.com>

> I am rather certain this is a javac bug -- though it would be good to
> /prove /that from a javac command line so as to get some focus on the real
> issue here.
>
> I believe Sun should take this particular issue seriously.  We've seen this
> before where A depends on B which /internally/ depends upon C and then
> suddenly one has to have C around to compile A.  That extends compilation
> dependencies across decoupling points one designs in and breaks library
> opacity / encapsulation.  This whole issue needs to be taken seriously and
> nailed by Sun.  It impacts Ant, of course, but this in turn impacts
> NetBeans.  It also impacts everything that uses their compiler rather than
> JDT.  Overall this issue should not be tolerated.
>
> --
> Jess Holle
>
>
> Stefan Bodewig wrote:
>
>> On Tue, 4 Nov 2008, Sergey Bondarenko <en...@gmail.com> wrote:
>>
>>
>>
>>> Regarding compilation issue, it looks like Ant javac task does not
>>> handle "includes" and "excludes" attributes correctly when it is
>>> used with JDK 6.  But it works properly with JDK 5.
>>>
>>>
>>
>> Uhm, no.
>>
>> includes/excludes controls which source files are being sent to
>> javac's command line.  If javac decides that it needs to compile
>> additional classes that it can find inside the source path, then there
>> is nothing that Ant can do.
>>
>> Inside the manual page for the javac task you will find (under
>> examples):
>>
>> ,----
>> | If you wish to compile only files explicitly specified and disable
>> | javac's default searching mechanism then you can unset the sourcepath
>> | attribute:
>> | |   <javac sourcepath="" srcdir="${src}"
>> |          destdir="${build}" >
>> |     <include name="**/*.java"/>
>> |     <exclude name="**/Example.java"/>
>> |   </javac>
>> | | That way the javac will compile all java source files under "${src}"
>> | directory but skip the examples. The compiler will even produce errors
>> | if some of the non-example files refers to them.
>> `----
>>
>> Stefan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>> For additional commands, e-mail: dev-help@ant.apache.org
>>
>>
>>
>>
>
>

Re: javac task problem in Java 6

Posted by Jess Holle <je...@ptc.com>.
Steve Loughran wrote:
> Jesse Glick wrote:
>> Jess Holle wrote:
>>> We've seen this before where A depends on B which /internally/ 
>>> depends upon C and then suddenly one has to have C around to compile A.
>>
>> Although this is not forbidden by the JLS (as far as I know), it does 
>> seem undesirable. If you know of particular examples which can be 
>> expressed as minimal test cases, I would encourage you to file bug 
>> reports for the compiler.
> Not ever seen that.
>
> I have just been burned today by the fact that Java6 lets you do an 
> @Overrides on any method that implements an interface; I'd been using 
> that to indicate which methods were interface implementations. Java5 
> says @Overrides is only for non-abstract methods, hence breaks.
Yes, that's a really obnoxious failing in Java 5.

It's good that it was fixed in Java 6.  It would have been even better 
if it had been fixed in a Java 5 update.

--
Jess Holle


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: javac task problem in Java 6

Posted by Steve Loughran <st...@apache.org>.
Jesse Glick wrote:
> Jess Holle wrote:
>> We've seen this before where A depends on B which /internally/ depends 
>> upon C and then suddenly one has to have C around to compile A.
> 
> Although this is not forbidden by the JLS (as far as I know), it does 
> seem undesirable. If you know of particular examples which can be 
> expressed as minimal test cases, I would encourage you to file bug 
> reports for the compiler.
> 

Not ever seen that.

I have just been burned today by the fact that Java6 lets you do an 
@Overrides on any method that implements an interface; I'd been using 
that to indicate which methods were interface implementations. Java5 
says @Overrides is only for non-abstract methods, hence breaks.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: javac task problem in Java 6

Posted by Jesse Glick <je...@sun.com>.
Jess Holle wrote:
> We've seen this before where A depends on B which /internally/ depends upon C and then suddenly one has to have C around to compile A.

Although this is not forbidden by the JLS (as far as I know), it does seem undesirable. If you know of particular examples which can be expressed as minimal test cases, I 
would encourage you to file bug reports for the compiler.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: javac task problem in Java 6

Posted by Jess Holle <je...@ptc.com>.
I am rather certain this is a javac bug -- though it would be good to 
/prove /that from a javac command line so as to get some focus on the 
real issue here.

I believe Sun should take this particular issue seriously.  We've seen 
this before where A depends on B which /internally/ depends upon C and 
then suddenly one has to have C around to compile A.  That extends 
compilation dependencies across decoupling points one designs in and 
breaks library opacity / encapsulation.  This whole issue needs to be 
taken seriously and nailed by Sun.  It impacts Ant, of course, but this 
in turn impacts NetBeans.  It also impacts everything that uses their 
compiler rather than JDT.  Overall this issue should not be tolerated.

--
Jess Holle

Stefan Bodewig wrote:
> On Tue, 4 Nov 2008, Sergey Bondarenko <en...@gmail.com> wrote:
>
>   
>> Regarding compilation issue, it looks like Ant javac task does not
>> handle "includes" and "excludes" attributes correctly when it is
>> used with JDK 6.  But it works properly with JDK 5.
>>     
>
> Uhm, no.
>
> includes/excludes controls which source files are being sent to
> javac's command line.  If javac decides that it needs to compile
> additional classes that it can find inside the source path, then there
> is nothing that Ant can do.
>
> Inside the manual page for the javac task you will find (under
> examples):
>
> ,----
> | If you wish to compile only files explicitly specified and disable
> | javac's default searching mechanism then you can unset the sourcepath
> | attribute:
> | 
> |   <javac sourcepath="" srcdir="${src}"
> |          destdir="${build}" >
> |     <include name="**/*.java"/>
> |     <exclude name="**/Example.java"/>
> |   </javac>
> | 
> | That way the javac will compile all java source files under "${src}"
> | directory but skip the examples. The compiler will even produce errors
> | if some of the non-example files refers to them.
> `----
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
>   


Re: javac task problem in Java 6

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 4 Nov 2008, Sergey Bondarenko <en...@gmail.com> wrote:

> Regarding compilation issue, it looks like Ant javac task does not
> handle "includes" and "excludes" attributes correctly when it is
> used with JDK 6.  But it works properly with JDK 5.

Uhm, no.

includes/excludes controls which source files are being sent to
javac's command line.  If javac decides that it needs to compile
additional classes that it can find inside the source path, then there
is nothing that Ant can do.

Inside the manual page for the javac task you will find (under
examples):

,----
| If you wish to compile only files explicitly specified and disable
| javac's default searching mechanism then you can unset the sourcepath
| attribute:
| 
|   <javac sourcepath="" srcdir="${src}"
|          destdir="${build}" >
|     <include name="**/*.java"/>
|     <exclude name="**/Example.java"/>
|   </javac>
| 
| That way the javac will compile all java source files under "${src}"
| directory but skip the examples. The compiler will even produce errors
| if some of the non-example files refers to them.
`----

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: javac task problem in Java 6

Posted by Sergey Bondarenko <en...@gmail.com>.
Hi guys!

Thanks for you answers! I am sorry that I did not answer your letters
earlier, I was out of the office.

Regarding compilation issue, it looks like Ant javac task does not handle
"includes" and "excludes" attributes correctly when it is used with JDK 6.
But it works properly with JDK 5.

Please try attached issue demo.
In build.xml we are trying to compile A.java, using b.jar (with B.class) in
classpath.

<project default="compile">
    <target name="compile">
        <javac srcdir="." destdir="." includes="A.java" excludes="B.java">
            <classpath>
                <pathelement path="b.jar"/>
            </classpath>
        </javac>
    </target>
</project>

We explicitly exclude B.java from compilation.
JDK 5 in this case creates A.class and build finished succesfully.
JDK 6 creates A.class, and then *unexpectedly* tries to compile B.java
(though B.java is excluded from compilation in javac task).

In my case it is the root of compilation problem.


Thanks for helping me!

Regards,
Sergey Bondarenko.

2008/11/4 Jesse Glick <je...@sun.com>

> Sergey Bondarenko wrote:
>
>> Imagine situation when you have 3 classes with dependencies between them:
>> A -> B -> C
>>
>> Then you compile C.java and pack into c.jar
>> Then you compile B.java, using c.jar in classpath, and pack it into b.jar
>>
>> Then you compile A.java, using b.jar.
>>
>> It works properly in Java 5, but fails in Java 6: compiler can not resolve
>> dependency B->C (though you compile only A class).
>>
>
> As Stefan said, this is likely not related to Ant as such.
>
> As far as I am aware, the JLS does not specify under which conditions a
> Java compiler might require transitive dependencies to be present on the
> classpath, beyond the obvious fact that if the content of such a dependency
> could possibly affect the generated bytecode then it must be present. I seem
> to recall that Jikes used to behave differently than javac, and I am not
> that surprised if JDK 5 javac behaves differently from JDK 6 javac. To be on
> the safe side, you should include c.jar in the classpath when compiling
> A.java.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

Re: javac task problem in Java 6

Posted by Jesse Glick <je...@sun.com>.
Sergey Bondarenko wrote:
> Imagine situation when you have 3 classes with dependencies between them:
> A -> B -> C
> 
> Then you compile C.java and pack into c.jar
> Then you compile B.java, using c.jar in classpath, and pack it into b.jar
> 
> Then you compile A.java, using b.jar.
> 
> It works properly in Java 5, but fails in Java 6: compiler can not resolve
> dependency B->C (though you compile only A class).

As Stefan said, this is likely not related to Ant as such.

As far as I am aware, the JLS does not specify under which conditions a Java compiler might require transitive dependencies to be present on the classpath, beyond the 
obvious fact that if the content of such a dependency could possibly affect the generated bytecode then it must be present. I seem to recall that Jikes used to behave 
differently than javac, and I am not that surprised if JDK 5 javac behaves differently from JDK 6 javac. To be on the safe side, you should include c.jar in the classpath 
when compiling A.java.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org