Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » javac compiles, eclipse doesn't
javac compiles, eclipse doesn't [message #258404] Mon, 02 February 2009 08:09 Go to next message
Eclipse UserFriend
Originally posted by: arend.reinersdorff.de

Hi,

I stumbled upon a piece of code that compiles with Sun's javac, but not
with the Eclipse Batch Compiler:

import java.lang.reflect.Constructor;
import java.beans.ConstructorProperties;

public class Test{
void test() {
//remove comments around <?>
//and this compiles fine with the eclipse batch compiler
for (Constructor/*<?>*/ constr : Object.class.getConstructors()) {
constr.getAnnotation(ConstructorProperties.class).value();
}
}
}

- Is it intended that the two compilers have different behavior in some
cases?
- If it's not intended, which compiler is right? Should this code compile
or not?

Thanks.
Re: javac compiles, eclipse doesn't [message #258407 is a reply to message #258404] Mon, 02 February 2009 08:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mauro.molinari.cardinis.com

Arend v. Reinersdorff ha scritto:
> Hi,
>
> I stumbled upon a piece of code that compiles with Sun's javac, but not
> with the Eclipse Batch Compiler:
>
> import java.lang.reflect.Constructor;
> import java.beans.ConstructorProperties;
>
> public class Test{
> void test() {
> //remove comments around <?>
> //and this compiles fine with the eclipse batch compiler
> for (Constructor/*<?>*/ constr : Object.class.getConstructors()) {
> constr.getAnnotation(ConstructorProperties.class).value();
> }
> }
> }
>
> - Is it intended that the two compilers have different behavior in some
> cases?

It may happen if there's a bug in one of them. However, when javac has a
bug that is not clearly a bug (for instance, if the specifications are
not clear), the Eclise compiler tries to adhere to javac implementation,
rather than to provide its own.

> - If it's not intended, which compiler is right? Should this code
> compile or not?

It depends on which is the compiler that has a bug!

A JDT developer will surely give you a better answer on whether your
specific case should be considered a bug of the Eclipse compiler.

Mauro.
Re: javac compiles, eclipse doesn't [message #258416 is a reply to message #258404] Mon, 02 February 2009 09:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 2/2/2009 8:09 AM, Arend v. Reinersdorff wrote:
> Hi,
>
> I stumbled upon a piece of code that compiles with Sun's javac, but not
> with the Eclipse Batch Compiler:
>
> import java.lang.reflect.Constructor;
> import java.beans.ConstructorProperties;
>
> public class Test{
> void test() {
> //remove comments around <?>
> //and this compiles fine with the eclipse batch compiler
> for (Constructor/*<?>*/ constr : Object.class.getConstructors()) {
> constr.getAnnotation(ConstructorProperties.class).value();
> }
> }
> }

What is the error message that you get when it fails to compile?

Eric
Re: javac compiles, eclipse doesn't [message #258419 is a reply to message #258404] Mon, 02 February 2009 11:53 Go to previous messageGo to next message
Eclipse UserFriend
Arend v. Reinersdorff a écrit :
> - Is it intended that the two compilers have different behavior in some
> cases?
> - If it's not intended, which compiler is right? Should this code
> compile or not?
I opened bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=263258 to
track it down.
--
Olivier
Re: javac compiles, eclipse doesn't [message #258427 is a reply to message #258416] Tue, 03 February 2009 05:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: arend.reinersdorff.de

The error message is as follows. Only number (3.) is an error and prevents
compilation:

----------
1. WARNING in HelloWorld.java (at line 15)
for (java.lang.reflect.Constructor/*<?>*/ constr :
Object.class.getConstructors()) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Constructor is a raw type. References to generic type Constructor<T>
should be parameterized
----------
2. WARNING in HelloWorld.java (at line 16)

constr.getAnnotation(java.beans.ConstructorProperties.class) .value();
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type safety: The method getAnnotation(Class) belongs to the raw type
Constructor. References to generic type Constructor<T> should be
parameterized
----------
3. ERROR in HelloWorld.java (at line 16)

constr.getAnnotation(java.beans.ConstructorProperties.class) .value();
^^^^^
The method value() is undefined for the type Annotation
----------
3 problems (1 error, 2 warnings)
Re: javac compiles, eclipse doesn't [message #258459 is a reply to message #258427] Tue, 03 February 2009 08:50 Go to previous messageGo to next message
Eclipse UserFriend
Arend von Reinersdorff a écrit :
> The error message is as follows. Only number (3.) is an error and
> prevents compilation:
This ends up being a bug in javac.
--
Olivier
Re: javac compiles, eclipse doesn't [message #258463 is a reply to message #258419] Tue, 03 February 2009 09:15 Go to previous messageGo to next message
Eclipse UserFriend
Olivier Thomann <olivier_thomann@ca.ibm.com> writes:

> Arend v. Reinersdorff a écrit :
>> - Is it intended that the two compilers have different behavior in
>> some cases?
>> - If it's not intended, which compiler is right? Should this code
>> compile or not?
> I opened bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=263258 to
> track it down.

That has since been marked as a duplicate of another bug and following
the trail from there leads you to:

<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6730568>

My reading of that bug is that javac has the bug and the Eclipse
compiler behaves in the intended way.

--
Owen Rees; speaking personally, and not on behalf of HP.
========================================================
Hewlett-Packard Limited. Registered No: 690597 England
Registered Office: Cain Road, Bracknell, Berks RG12 1HN
Re: javac compiles, eclipse doesn't [message #258478 is a reply to message #258463] Tue, 03 February 2009 13:34 Go to previous message
Eclipse UserFriend
Originally posted by: arend.reinersdorff.de

Good to know!

Thanks everyone for digging this up.
Previous Topic:Retrieving all classes from IProject
Next Topic:Extends JDT to support @java
Goto Forum:
  


Current Time: Thu Apr 17 21:38:46 EDT 2025

Powered by FUDForum. Page generated in 0.04185 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top