I use JAXB 2 to parse an XML file against an XSD schema and the XML tags are automatically unmarshalled during ant build to Java classes. Some enums
are created. The code is:
@XmlType(name = "binQuality")
@XmlEnum
public enum BinQuality {
GOOD,
BAD,
UGLY,
NULL;
public String value() {
return name();
}
public static BinQuality fromValue(String v) {
return valueOf(v);
}
}
In my code I call:
BinQuality bq = BinQuality.valueOf(him.getToBinQuality());
in a loop and I get the exception only in the 91st iteration.
******* UPDATED *******
him.getToBinQuality()
does return a valid enum (GOOD/BAD/UGLY/NULL). Below is an excerpt of logs.
....
2011-07-18 15:28:09 DEBUG (com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl:183) -> class com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl|exportToXml|him.getToBin():89|him.getToBinQuality():BAD
2011-07-18 15:28:09 DEBUG (com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl:183) -> class com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl|exportToXml|him.getToBin():90|him.getToBinQuality():UGLY
2011-07-18 15:28:09 DEBUG (com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl:183) -> class com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl|exportToXml|him.getToBin():91|him.getToBinQuality():BAD
2011-07-18 15:28:09 WARN (org.apache.struts.action.RequestProcessor:538) -> Unhandled Exception thrown: class java.lang.IllegalArgumentException
This seems really mysterious.
Java version used is 1.5.
Appreciate it.
Will
This is because no enum value could be found for your 91th entry. What is the value of the failed String?
Either your XML does not have a valid ENUM value (like 'good' in lowercase) or it has an empty tag, because if you try to eval an enum element via MyEnum.valueOf(null)
it will throw an IllegalArgumentException.
Most probably this is because that him.getToBinQuality()
does not return the valid string which is in this case String should be 'GOOD|BAD|UGLY|NULL'
You can easily debug this by printing the value on the log.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With