castor-data-binding / castor

http://castor-data-binding.github.io/castor/
35 stars 29 forks source link

NullPointerException issue #72

Open jiangdequan opened 6 years ago

jiangdequan commented 6 years ago

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 commented 6 years ago

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

jiangdequan commented 6 years ago

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

wguttmn commented 6 years ago

Apologies, but I am not capable of reading Chinese (presumably), and there does not seem to be an obvious language switcher either. Can you please upload to e.g. wetransfer.com pr attach to the GitHub issue ?

Regards Werner

On 30.11.2017, at 03:54, Jiang Dequan notifications@github.com wrote:

You can get the maven project whick I used to generate source codes form the link below https://pan.baidu.com/s/1bL5jQ2 https://pan.baidu.com/s/1bL5jQ2 In eclipse, input 'clean castor:generate install' to run, you may reproduce these problems.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/castor-data-binding/castor/issues/72#issuecomment-348067381, or mute the thread https://github.com/notifications/unsubscribe-auth/AAh_0TUT38F4gQ7e4Tf14iV9swJAATMWks5s7hj9gaJpZM4QsyuO.

jiangdequan commented 6 years ago

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