Skip to content
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

NullPointerException issue #72

Open
jiangdequan opened this issue Nov 28, 2017 · 4 comments
Open

NullPointerException issue #72

jiangdequan opened this issue Nov 28, 2017 · 4 comments

Comments

@jiangdequan
Copy link

Hi, wguttmn!
I met a NullPointerException, the following is error log

Caused by: java.lang.NullPointerException
	at org.exolab.castor.builder.info.CollectionInfo.<init>(CollectionInfo.java:100)
	at org.exolab.castor.builder.info.CollectionInfoJ2.<init>(CollectionInfoJ2.java:70)
	at org.exolab.castor.builder.factory.FieldInfoFactory.createCollection(FieldInfoFactory.java:208)
	at org.exolab.castor.builder.factory.FieldInfoFactory.createCollection(FieldInfoFactory.java:181)
	at org.exolab.castor.builder.factory.MemberFactory.createFieldInfoForContent(MemberFactory.java:229)
	at org.exolab.castor.builder.factory.SourceFactory.processComplexType(SourceFactory.java:2076)
	at org.exolab.castor.builder.factory.SourceFactory.processComplexType(SourceFactory.java:812)
	at org.exolab.castor.builder.factory.SourceFactory.createSourceCode(SourceFactory.java:368)
	at org.exolab.castor.builder.SourceGenerator.createClasses(SourceGenerator.java:932)
	at org.exolab.castor.builder.SourceGenerator.generateAllClassFiles(SourceGenerator.java:786)
	at org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:744)
	at org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:690)
	at org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:587)

Based on the logs:
the error happend at CollectionInfo.java in line 100

public CollectionInfo(final XSType contentType, final String name, final String elementName,
      final boolean useJava50, final FieldMemberAndAccessorFactory memberAndAccessorFactory,
      final FieldMemberAndAccessorFactory contentMemberAndAccessorFactory) {
    super(XSCollectionFactory.createCollection(SourceGeneratorConstants.FIELD_INFO_VECTOR,
        contentType, useJava50), name, memberAndAccessorFactory);

    **if (elementName.charAt(0) == '_') {// error occurred there**
      this._elementName = elementName.substring(1);
    } else {
      this._elementName = elementName;
    }

    this._methodSuffix =
        memberAndAccessorFactory.getJavaNaming().toJavaClassName(this.getElementName());
    this._parameterPrefix =
        memberAndAccessorFactory.getJavaNaming().toJavaMemberName(this.getElementName());
    this._content =
        new FieldInfo(contentType, "v" + this.getMethodSuffix(), contentMemberAndAccessorFactory);

    // indicates that - per definition - we are dealing with multi-valuedness
    new XMLInfoNature(this).setMultivalued(true);
  } // -- CollectionInfo

source code of (MemberFactory.java:229), the input elementName is null

public FieldInfo createFieldInfoForContent(final XMLBindingComponent component,
      final XSType xsType, final boolean useJava50) {
    String fieldName = "content";// new xsType()???
    if (getConfig().useOldFieldNaming()) {
      StringUtils.leftPad(fieldName, 1, '_');
    }
    if (component.getContentMemberName() != null) {
      fieldName = component.getContentMemberName();
    }
    FieldInfo fInfo = null;
    if (xsType.isCollection()) {
      fInfo = this.getInfoFactory().createCollection(((XSListType) xsType).getContentType(),
          fieldName, null, getJavaNaming(), useJava50);// line 229
    } else {
      fInfo = this.getInfoFactory().createFieldInfo(xsType, fieldName);
    }
    fInfo.setComment("internal content storage");
    if (xsType instanceof XSString) {
      fInfo.setDefaultValue("\"\"");
    }
    if (fInfo.hasNature(XMLInfoNature.class.getName())) {
      XMLInfoNature xmlNature = new XMLInfoNature(fInfo);
      xmlNature.setNodeType(NodeType.TEXT);
      xmlNature.setRequired(false);
      xmlNature.setNodeName("#text");
    }
    return fInfo;
  }

Can you help me find out the reson? Many thanks.

@wguttmn
Copy link
Contributor

wguttmn commented Nov 28, 2017

Can you please provide a (minimal) XML schema that I can use to reproduce this problem ?

@jiangdequan
Copy link
Author

https://github.com/iata-ndc/ndc-xsd-162
From there you can find all the xsd files that I used.

@wguttmn
Copy link
Contributor

wguttmn commented Nov 30, 2017 via email

@jiangdequan
Copy link
Author

Oh,it`s my mistake.
https://github.com/jiangdequan/castor/tree/master/demo-source-generate
I push the demo there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants