-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPE in ClassDiscoverer::handleXmlElement
#42
Comments
Looking at this again, if the jfv.annotations().stream()
.filter(jau -> Utils.isXmlElements(jau.getAnnotationClass()))
.map(jau -> (JAnnotationArrayMember) jau.getAnnotationMembers().get("value"))
.flatMap(value -> value.annotations().stream())
.forEach(anno -> {
JAnnotationValue type = anno.getAnnotationMembers().get("type");
if (type != null) {
handleXmlElement(outline, directClasses, type);
} else {
if (jfv.type().elementType() != null) { // Adapt this for List<T>. This only works for T[].
handleXmlElement(outline, directClasses, jfv.type().elementType());
}
}
}); And changing the final argument to |
@Warpten thanks for reporting this. Can you provide a full example so I can add it as a test case? I'm wondering if the else should invoke the JClass elementType = (JClass) jfv.type().elementType();
List<JClass> typeParameters = elementType.getTypeParameters();
if (typeParameters != null && typeParameters.get(0) != null) {
addIfDirectClass(directClasses, typeParameters.get(0));
} else {
addIfDirectClass(directClasses, elementType);
} It would help to have some schemas and different settings to test with. |
Sorry, I forgot about this. A test case should be as simple as reusing the <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="DerivedA" type="DerivedA"/>
<xs:element name="BaseType" type="BaseType"/>
<xs:element name="TypeList" type="TypeList"/>
<xs:element name="DerivedD" type="DerivedD" />
<xs:complexType name="TypeList">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="DerivedA"/>
<xs:element ref="BaseType"/>
<xs:element ref="DerivedD"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="BaseType" />
<xs:complexType name="DerivedA">
<xs:complexContent>
<xs:extension base="BaseType">
<xs:sequence />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="DerivedD">
<xs:complexContent>
<xs:extension base="BaseType">
<xs:sequence />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema> This is enough to trigger the NPE when used with the As far as fixing this goes, I also tried this approach: jfv.annotations().stream()
.filter(jau -> Utils.isXmlElements(jau.getAnnotationClass()))
.map(jau -> (JAnnotationArrayMember) jau.getAnnotationMembers().get("value"))
.flatMap(value -> value.annotations().stream())
.forEach(anno -> {
JAnnotationValue type = anno.getAnnotationMembers().get("type");
if (type != null) {
handleXmlElement(outline, directClasses, type);
} else {
JClass jcs = (JClass) jfv.type();
if (Objects.equals(outline.getCodeModel().ref(List.class), jcs.erasure())) {
JClass elementType = jcs.getTypeParameters().get(0);
handleXmlElement(outline, directClasses, elementType);
} else {
handleXmlElement(outline, directClasses, jcs);
}
}
}); But I don't know that it is correct. |
@Warpten I added your schema as a test case and took the simple approach of checking for the type and then handling an array or collection. Thanks for the report and suggestions. |
ClassDiscoverer#handleXmlElement
fails with anNPE
ontype
when processing the following XSD file. This is (I think) because the generated Java classes (at least, using the codehaus plugin) do not have a type associated with theXmlElement
annotation for the base type:I just ended up checking for nullity and that fixed it (obviously), but I'm not sure that that's the correct fix.
I can't modify the .xsd files as they are exposed and generated by a service I consume.
The text was updated successfully, but these errors were encountered: