Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Compiling annotations with inconsistant behavior
Compiling annotations with inconsistant behavior [message #334182] Fri, 23 January 2009 17:35 Go to next message
Priyajeet is currently offline PriyajeetFriend
Messages: 4
Registered: July 2009
Junior Member
Consider the following code scenerios...

// Case 1
// Code shows error in eclipse
@MappedSuperclass
class Parent
{
public static final String TABLE = "PARENT";
public static final InheritanceType INH = InheritanceType.SINGLE_TABLE;
...
}


@Entity
@Table(name=Parent.TABLE) <<< Works fine
@Inheritance(strategy=Parent.INH) <<< ERROR, requires enum constant
class Child extends Parent
{
...
}



// Case 2
// Code shows no error in eclipse
// But fails to compile via command line using say maven
@MappedSuperclass
class Parent
{
public static final String TABLE = "PARENT";
public static final int INH = 0;
...
}


@Entity
@Table(name=Parent.TABLE) <<< Works fine everywhere
@Inheritance(strategy = Parent.INH == 0
? InheritanceType.X
: InheritanceType.Y) <<< NO ERROR in eclipse
class Child extends Parent
{
...
}

The latter case fails compile time via maven with the same error as
before, that the annotation requires an enum constant value for
Inheritance.

Why does eclipse have an inconsistant behvaior in that case?
I am using Ganymede and JDK 1.6 (however same behavior seen with JDK 1.5)

Thanks.
Re: Compiling annotations with inconsistant behavior [message #334183 is a reply to message #334182] Fri, 23 January 2009 17:38 Go to previous messageGo to next message
Priyajeet is currently offline PriyajeetFriend
Messages: 4
Registered: July 2009
Junior Member
small note: ignore the fact that I used .X and .Y for case 2.
Everything is accurate to javax.persistance.InheritanceType enum.
All imports are correct.
Re: Compiling annotations with inconsistant behavior [message #334190 is a reply to message #334183] Sun, 25 January 2009 01:54 Go to previous messageGo to next message
Walter Harley is currently offline Walter HarleyFriend
Messages: 847
Registered: July 2009
Senior Member
"Priyajeet " <priyajeet.hora@gmail.com> wrote in message
news:e4ffaf5b42e64efbd92a296dc955d5b8$1@www.eclipse.org...
> small note: ignore the fact that I used .X and .Y for case 2.
> Everything is accurate to javax.persistance.InheritanceType enum.
> All imports are correct.

For future reference, questions like this are best posted to
eclipse.tools.jdt, not eclipse.platform.

For those (like me) who don't have the JPA annotations memorized, the
following code will reproduce the problem:

public class Foo {
protected enum E { E1, E2 }

protected @interface AnnoE {
E value();
}

@AnnoE(true ? E.E1 : E.E2)
public void foo() {}
}


Eclipse does not error; javac 1.6 does:

D:\eclipse\ws\priyajeet\Foo\src>javac -d ../bin -cp . Foo.java
Foo.java:8: an enum annotation value must be an enum constant
@AnnoE(true ? E.E1 : E.E2)
^
1 error


Now, whether this is a javac bug or an Eclipse bug is something for the
language lawyers to wrangle over. The rules about enum constants are a bit
funky, and so are the rules about the ternary operator; answering questions
like that usually involves digging into the nitty gritty details of the JLS
and sometimes even then there are ambiguities.

Anyway, I didn't see an existing bug about it in either the Sun or Eclipse
bug databases, so I've entered https://bugs.eclipse.org/262304 to track it.
Re: Compiling annotations with inconsistant behavior [message #334205 is a reply to message #334190] Mon, 26 January 2009 16:55 Go to previous message
Walter Harley is currently offline Walter HarleyFriend
Messages: 847
Registered: July 2009
Senior Member
"Walter Harley" <eclipse@cafewalter.com> wrote in message
news:glggnv$ri4$1@build.eclipse.org...
>
> Anyway, I didn't see an existing bug about it in either the Sun or Eclipse
> bug databases, so I've entered https://bugs.eclipse.org/262304 to track
> it.

The JDT guys have identified this as an Eclipse bug, and have fixed it for
3.5 M5.
Previous Topic:LTK rename refactoring - overriding the icons
Next Topic:Update-site not found new features
Goto Forum:
  


Current Time: Fri Apr 26 16:24:12 GMT 2024

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

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

Back to the top