What kinds of things could cause a class' annotations to not beavailable?

D

david.karr

I have a situation with a simple Java class with annotations, using
JDK 1.5.

The class and method looks perfectly fine in Eclipse, and the
annotations on the class and method appear to be fine. When I deploy
this class with ATG Dynamo, inside WebLogic 10.1, when I call
"getAnnotation()" on the method object, I get an empty array. I know
WebLogic has no issues with annotations, but I'm wondering if there's
something about the use of ATG Dynamo that messes something up.

I was able to work around the problem by doing my initializations
entirely in Spring, but I was hoping to have annotation configuration
available.

There's no point in showing the code, as it's very simple and is based
on simple working examples that I've seen.

What I'd like to know is what sorts of things in the Java environment
could cause a class to "lose" its annotations. I've heard that OSGi
can cause this, but I don't think OSGi is being used here.
 
R

Roedy Green

I have a situation with a simple Java class with annotations, using
JDK 1.5.

Annotations are a feature of JDK 1.6+. If you compile with JDK 1.6
and target -1.5 they are simply ignored.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"There is an evil which ought to be guarded against, in the indefinite accumulation of property,
from the capacity of holding it in perpetuity by... corporations.
The power of all corporations aught to be limited in this respect.
The growing wealth acquired by them never fails to be a source of abuses."
~ James Madison (born: 1751-03-16 died: 1836-06-28 at age: 85)
 
B

Bill McCleary

Roedy said:
Annotations are a feature of JDK 1.6+. If you compile with JDK 1.6
and target -1.5 they are simply ignored.

Surely ye jest? Annotations were introduced at the same time as the
for-each loop and generics.

You can Google it if you don't believe me (or just click this:
http://en.wikipedia.org/wiki/Java_annotation#History
and read the History section halfway down the page from there).

Not to mention that the general pattern has been new features in
odd-numbered releases, bugfixes and performance tuning and minor API
addenda in even-numbered releases, since 1.3.
 
R

Roedy Green

Surely ye jest? Annotations were introduced at the same time as the
for-each loop and generics.

The URL you gave says "Annotations became available in the language
itself beginning with version 1.5 of the JDK. A provisional interface
for compile-time annotation processing was provided by the apt tool in
JDK version 1.5, and was formalized through JSR-269 and integrated
into the javac compiler in version 1.6."

It sounds to me like annotations in 1.5 would have at best been
ignored by Javac. Language lawyer??
--
Roedy Green Canadian Mind Products
http://mindprod.com

"There is an evil which ought to be guarded against, in the indefinite accumulation of property,
from the capacity of holding it in perpetuity by... corporations.
The power of all corporations aught to be limited in this respect.
The growing wealth acquired by them never fails to be a source of abuses."
~ James Madison (born: 1751-03-16 died: 1836-06-28 at age: 85)
 
L

Lew

Roedy said:
The URL you gave says "Annotations became available in the language
itself beginning with version 1.5 of the JDK. A provisional interface
for compile-time annotation processing was provided by the apt tool in
JDK version 1.5, and was formalized through JSR-269 and integrated
into the javac compiler in version 1.6."

It sounds to me like annotations in 1.5 would have at best been
ignored by Javac. Language lawyer??

They're in the JLS third edition, the definition of the Java language for Java
5 onward. See my other post in this thread.
 
M

Mike Schilling

Roedy said:
The URL you gave says "Annotations became available in the language
itself beginning with version 1.5 of the JDK. A provisional
interface
for compile-time annotation processing

That is, users can now put hooks into javac to do custom annotation
processings during compilation.
was provided by the apt tool in
JDK version 1.5, and was formalized through JSR-269 and integrated
into the javac compiler in version 1.6."

It sounds to me like annotations in 1.5 would have at best been
ignored by Javac.

Nope. Normal (as opposed to customized) annotation processing was
intoduced in 1.5, and many frameworks (e.g. JAX-WS) use them.
 
A

Andreas Leitgeb

david.karr said:
I have a situation with a simple Java class with annotations, using
JDK 1.5.
The class and method looks perfectly fine in Eclipse, and the
annotations on the class and method appear to be fine. When I deploy
this class with ATG Dynamo, inside WebLogic 10.1, when I call
"getAnnotation()" on the method object, I get an empty array.

Just a wild guess: in case you use your own annotations, did you specify
their RetentionPolicy ?

<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Retention.html>
 
D

Donkey Hottie

Somehow I don't think they'll be ignored with "-target
1.5".

Absolutely not. That is exactly what I do, compile with JDK6 with -target
1.5, and annotations just work.
 
D

Daniel Pitts

Roedy said:
The URL you gave says "Annotations became available in the language
itself beginning with version 1.5 of the JDK. A provisional interface
for compile-time annotation processing was provided by the apt tool in
JDK version 1.5, and was formalized through JSR-269 and integrated
into the javac compiler in version 1.6."

It sounds to me like annotations in 1.5 would have at best been
ignored by Javac. Language lawyer??
I know that annotations worked in 1.5 (and we're available reflectively).
My guess is that in 1.6 they added support to have compile-time effects
of annotations, but I don't know that for sure.
 
J

Joshua Cranmer

Roedy said:
The URL you gave says "Annotations became available in the language
itself beginning with version 1.5 of the JDK. A provisional interface
for compile-time annotation processing was provided by the apt tool in
JDK version 1.5, and was formalized through JSR-269 and integrated
into the javac compiler in version 1.6."

The annotation processing tool was separate from the compiler in 1.5,
but they decided in 1.6 to integrate it into the javac API.
It sounds to me like annotations in 1.5 would have at best been
ignored by Javac. Language lawyer??

Nope. They were fully functional in 1.5 javac (as some would have to be
reified to the class files). All that the text is saying is that
user-customizable annotation processing was separated from the compiler
in 1.5.
 
D

David Karr

The annotation processing tool was separate from the compiler in 1.5,
but they decided in 1.6 to integrate it into the javac API.


Nope. They were fully functional in 1.5 javac (as some would have to be
reified to the class files). All that the text is saying is that
user-customizable annotation processing was separated from the compiler
in 1.5.

Just so it's clear, I'm compiling with JDK 1.5, with a "source" value
of "1.5".

I'm still looking for some idea of why the annotations appear to be
unavailable at runtime. I've verified the annotations are stored in
the class file, using JD-GUI to examine the class file. As I
mentioned earlier, the retention policy is RUNTIME, so they should be
available. Is there something about Spring, WebLogic 10.1, or ATG
Dynamo that might cause this to happen?
 
D

Daniel Pitts

David said:
Just so it's clear, I'm compiling with JDK 1.5, with a "source" value
of "1.5".

I'm still looking for some idea of why the annotations appear to be
unavailable at runtime. I've verified the annotations are stored in
the class file, using JD-GUI to examine the class file. As I
mentioned earlier, the retention policy is RUNTIME, so they should be
available. Is there something about Spring, WebLogic 10.1, or ATG
Dynamo that might cause this to happen?
Perhaps you should provide an SSCCE <http://sscce.org> which
demonstrates your troubles.
 
D

David Karr

The annotation processing tool was separate from the compiler in 1.5,
but they decided in 1.6 to integrate it into the javac API.


Nope. They were fully functional in 1.5 javac (as some would have to be
reified to the class files). All that the text is saying is that
user-customizable annotation processing was separated from the compiler
in 1.5.

Just so it's clear, I'm compiling with JDK 1.5, with a "source" value
of "1.5".

I'm still looking for some idea of why the annotations appear to be
unavailable at runtime. I've verified the annotations are stored in
the class file, using JD-GUI to examine the class file. As I
mentioned earlier, the retention policy is RUNTIME, so they should be
available. Is there something about Spring, WebLogic 10.1, or ATG
Dynamo that might cause this to happen?
 
D

David Karr

The annotation processing tool was separate from the compiler in 1.5,
but they decided in 1.6 to integrate it into the javac API.


Nope. They were fully functional in 1.5 javac (as some would have to be
reified to the class files). All that the text is saying is that
user-customizable annotation processing was separated from the compiler
in 1.5.

Just so it's clear, I'm compiling with JDK 1.5, with a "source" value
of "1.5".

I'm still looking for some idea of why the annotations appear to be
unavailable at runtime. I've verified the annotations are stored in
the class file, using JD-GUI to examine the class file. As I
mentioned earlier, the retention policy is RUNTIME, so they should be
available. Is there something about Spring, WebLogic 10.1, or ATG
Dynamo that might cause this to happen?
 
D

David Karr

Just so it's clear, I'm compiling with JDK 1.5, with a "source" value
of "1.5".

I'm still looking for some idea of why the annotations appear to be
unavailable at runtime.  I've verified the annotations are stored in
the class file, using JD-GUI to examine the class file.  As I
mentioned earlier, the retention policy is RUNTIME, so they should be
available.  Is there something about Spring, WebLogic 10.1, or ATG
Dynamo that might cause this to happen?

(Sorry about the double reply. An error occurred the first time, and
I thought that meant it didn't post it.)
 
T

Tom Anderson

Perhaps you should provide an SSCCE <http://sscce.org> which demonstrates
your troubles.

The problem is occurring inside a WebLogic/Spring/Dynamo stack. An SSCCE
could test if it happens outside that stack, but one which looks at in
context could not be both S and SC.

David, i'd take this to the ATG community forums if i were you. And if you
are or have a client who owns a license, to customer services.

tom
 
M

Mike Schilling

David said:
Just so it's clear, I'm compiling with JDK 1.5, with a "source" value
of "1.5".

I'm still looking for some idea of why the annotations appear to be
unavailable at runtime. I've verified the annotations are stored in
the class file, using JD-GUI to examine the class file. As I
mentioned earlier, the retention policy is RUNTIME, so they should be
available. Is there something about Spring, WebLogic 10.1, or ATG
Dynamo that might cause this to happen?

Complete wild-ass guess, but if the annotations are in the class files but
aren't making it into the runtime version of the class, I'd look at the
class loader.
 
D

David Karr

The problem is occurring inside a WebLogic/Spring/Dynamo stack. An SSCCE
could test if it happens outside that stack, but one which looks at in
context could not be both S and SC.

I appreciate that. For now, I'm going to continue doing experiments
inside the container, as it's giving me some interesting, if not yet
useful, information.
David, i'd take this to the ATG community forums if i were you. And if you
are or have a client who owns a license, to customer services.

Yeah. If you were in my shoes, you'd know how futile that is.

I've done some more experiments, which I'll detail here, along with
some indications of what frameworks I'm using.

The annotations I'm having trouble with are in the JAX-RS framework
used by Apache CXF. However, I realized that although the JAX-RS
annotations are invisible at runtime, the JAXB "@XmlRootElement"
annotation IS visible at runtime. I also defined a custom annotation
that is essentially identical to the JAX-RS "@Path" annotation, and
that is also visible at runtime.

My problem test case is a class referenced in a Spring context, both
in a plain Spring "bean", and in the jaxrs namespace. I also tried
cloning my problem test class and creating an instance of it from my
problem test class (it's not referenced from Spring), and analyzing
the annotations on that class. The cloned class had exactly the same
annotations symptoms as the original class. The JAX-RS annotations
were invisible, but the JAXB annotation and my custom annotation were
visible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top