Skip to main content

New Bug ? IllegalAnnotationExceptions !!!

15 replies [Last post]
gegles
Offline
Joined: 2005-10-05

Hi,

I have the following type defined in my schema:

JAXB-2.0 did not use to complain with this, but ... Ever since I started using weekly versions from a month or two ago, I get the following exception when trying to unmarshall a document containing a simple instance of this element:

Exception in thread "main" com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
@XmlValue is not allowed on a class that derives another class.
this problem is related to the following location:
at protected java.lang.String gov.lbl.dsd.dtf.Print.value
at gov.lbl.dsd.dtf.Print
at public gov.lbl.dsd.dtf.Print gov.lbl.dsd.dtf.ObjectFactory.createPrint()
at gov.lbl.dsd.dtf.ObjectFactory

Any idea. Is this a bug that got introduced ? Or should I do something differently ?

Thanks in advance for your help. Guillaume.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
malachid
Offline
Joined: 2004-05-16

That works! Nice!

bennop
Offline
Joined: 2006-06-29

I have the same problem! Anyway to make a patch for this??

kohsuke
Offline
Joined: 2003-06-09

This isn't a "bug" per se, in the sense that the RI is following what the spec says.

So we can't just "fix" it without violating the compatibility with the spec.

That said, I suspect you might be able to download the RI source code, and comment out the portion that does this error check. That would make it non-compatible, so there might be some legal implications, so check the license before you do it.

ms2scale
Offline
Joined: 2007-06-11

So it's not possible to derive generated classes from a superclass in jaxb 2.0 ?
Is this right?

kohsuke
Offline
Joined: 2003-06-09

No. There's customization if that's what you mean.

tomdotcom4
Offline
Joined: 2006-03-01

I've run into the same issue even in JAXB2.1. So I try to summarize: Even in JAXB2.1 there is NO possiblity to combine "@XmlValue" with "xjc:superClass". So effectivly using super classes is impossible.
Please correct me, if I am wrong. (I hope so!)

Update: I correct myself, and found a solution in JAXB2.1:
Just add @XmlTransient to the super class, and it works.

Message was edited by: tomdotcom4

cruisewave22
Offline
Joined: 2008-03-24

I tried this suggestion "Just add @XmlTransient to the super class, and it works", but I get a "annotation disallowed for this location". I am trying to place the annotation on a base abstract class. Any ideas?

kohsuke
Offline
Joined: 2003-06-09

Hmm. I should really check this. Does the Print class derive from any other class, as the error message says?

gegles
Offline
Joined: 2005-10-05

> Hmm. I should really check this. Does the Print class
> derive from any other class, as the error message
> says?

[b]
Well, now that you're asking, I realize that yes, all my JAXB generated classes derive from a base class Base (for the toString() method). But nothing fancy there:[/b]

public abstract class Base {

public String toString() {
return toString(this);
}

public String toString(Object action) {

....

if (action instanceof Print) {
return toString((Print)action);
}

...
return super.toString();
}

public static String toString(Print print) {
return "Print{ value=[" + print.getValue() + "]}";
}

}

[b]I just tried with removing . It WORKS !!!!

That's great for now, but I still really would like that feature. Let me know. Thanks. G.[/b]

kohsuke
Offline
Joined: 2003-06-09

This check is mandated by the spec, actually. I believe the motivation was to have a sound java->schema mapping, where in schema you can't derive your 'print' complex type from the following 'base' complex type (or can we? I forgot):
[code]

[/code]
It needs a spec level attention.

gegles
Offline
Joined: 2005-10-05

OK, but now, how can I implement a toString() for each of the JAXB-generated classes. I think in the long run it would be great for you guys to provide some kind of mechanism for JAXB users to be able to do that do that (maybe through an extension).

Thanks for your help. G

kohsuke
Offline
Joined: 2003-06-09

Yes, I completely understand why you'd want to do this. I need to check if this is possible wrt the schema spec, however. As I mentioned, I believe the primary motivation for this limitation is to make sure that the generated schema won't hit the limitation of the schema spec.

innanill
Offline
Joined: 2006-04-10

Has this been looked-into and/or resolved?
I'm experiencing this problem now, but we can't remove the base class!
Is there a workaround?

Thanks.

kohsuke
Offline
Joined: 2003-06-09

Since this needs a spec level change, we won't be able to do this by 2.0. The quickest fix would still have to wait the JAXB spec 2.1.

kohsuke
Offline
Joined: 2003-06-09

I filed Bug 6421447 for this