NullPointerException running DataNucleus Enhancer

2019-02-25 13:58发布

I am running DataNucleus enhancer from DOS as follows:

java -cp C:\Users\Chania\workspace\myproject\war\WEB-INF\classes\;C:\repo\datanucleus-full-3.1.0-release\lib\datanucleus-enhancer-3.1.0-release.jar;C:\repo\datanucleus-full-3.1.0-release\lib\datanucleus-core-3.1.0-release.jar;C:\repo\datanucleus-full-3.1.0-release\deps\jdo-api-3.1-SNAPSHOT-20110926.jar;C:\repo\datanucleus-full-3.1.0-release\lib\datanucleus-api-jdo-3.1.0-release.jar;C:\repo\datanucleus-full-3.1.0-release\deps\log4j-1.2.14.jar;C:\repo\datanucleus-full-3.1.0-release\deps\asm-4.0.jar -Dlog4j.configuration=file:C:\repo\datanucleus-full-3.1.0-release\log4j.properties org.datanucleus.enhancer.DataNucleusEnhancer -v C:\Users\Chania\workspace\myproject\war\WEB-INF\classes\com\myproject\domain\*.class > logfile.txt

The Java version that I'm using is:

java version "1.6.0_27"

The error that I'm getting is as follows:

 ...
 308  [main] DEBUG DataNucleus.Persistence  - Added converter for java.net.URI<->java.lang.String using org.datanucleus.store.types.converters.URIStringConverter
 308  [main] DEBUG DataNucleus.Persistence  - Added converter for java.net.URL<->java.lang.String using org.datanucleus.store.types.converters.URLStringConverter
 309  [main] DEBUG DataNucleus.Persistence  - Added converter for java.util.UUID<->java.lang.String using org.datanucleus.store.types.converters.UUIDStringConverter
 309  [main] DEBUG DataNucleus.Persistence  - TypeConverter for javax.time.calendar.LocalDate<->java.lang.String ignored since java type not present in CLASSPATH
 310  [main] DEBUG DataNucleus.Persistence  - TypeConverter for javax.time.calendar.LocalTime<->java.lang.String ignored since java type not present in CLASSPATH
 311  [main] DEBUG DataNucleus.Persistence  - TypeConverter for javax.time.calendar.LocalTime<->java.lang.Long ignored since java type not present in CLASSPATH
 312  [main] DEBUG DataNucleus.Persistence  - TypeConverter for javax.time.calendar.LocalDateTime<->java.lang.String ignored since java type not present in CLASSPATH
 312  [main] DEBUG DataNucleus.Persistence  - Type converter support loaded
 312  [main] DEBUG DataNucleus.MetaData  - MetaDataManager : Input=(XML,Annotations), XML-Validation=false, XML-Suffices=(persistence=*.jdo, orm=orm, query=*.jdoquery), JDO-listener=false
 338  [main] DEBUG DataNucleus.MetaData  - MetaData Management : Loading Metadata for classes "[com.myproject.domain.Record, com.myproject.domain.RecordSummary, com.myproject.domain.Comment]" ...
 411  [main] DEBUG DataNucleus.MetaData  - Class "com.myproject.domain.Record" has been specified with JDO annotations so using those.
 596  [main] DEBUG DataNucleus.MetaData  - Class "com.myproject.domain.RecordSummary" has been specified with JDO annotations so using those.
 600  [main] DEBUG DataNucleus.MetaData  - Class "com.myproject.domain.Comment" has been specified with JDO annotations so using those.
 Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
604  [main] ERROR DataNucleus.Enhancer  - DataNucleus Enhancer completed with an error. Please review the enhancer log for full details. Some classes may have been enhanced but some caused errors
 Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
org.datanucleus.exceptions.NucleusUserException: Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
    at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:536)
    at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:734)
    at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:525)
    at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1258)
Caused by: java.lang.NullPointerException
    at org.datanucleus.api.jdo.metadata.JDOAnnotationReader.processMemberAnnotations(JDOAnnotationReader.java:1682)
    at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getMetaDataForClass(AbstractAnnotationReader.java:206)
    at org.datanucleus.metadata.annotations.AnnotationManagerImpl.getMetaDataForClass(AnnotationManagerImpl.java:171)
    at org.datanucleus.metadata.MetaDataManager.loadAnnotationsForClass(MetaDataManager.java:2650)
    at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:496)
    ... 3 more
Nested Throwables StackTrace:
java.lang.NullPointerException
    at org.datanucleus.api.jdo.metadata.JDOAnnotationReader.processMemberAnnotations(JDOAnnotationReader.java:1682)
    at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getMetaDataForClass(AbstractAnnotationReader.java:206)
    at org.datanucleus.metadata.annotations.AnnotationManagerImpl.getMetaDataForClass(AnnotationManagerImpl.java:171)
    at org.datanucleus.metadata.MetaDataManager.loadAnnotationsForClass(MetaDataManager.java:2650)
    at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:496)
    at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:734)
    at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:525)
    at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1258)
DataNucleus Enhancer completed with an error. Please review the enhancer log for full details. Some classes may have been enhanced but some caused errors

The sources for the enhanced classes are as follows:

@PersistenceCapable(detachable = "true")
public class Record implements Serializable, Cacheable<String> {

    private static final long serialVersionUID = 9022509306966814904L;

    @PrimaryKey
    @Persistent(defaultFetchGroup = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
    private String id;

    @Name
    @Persistent(defaultFetchGroup = "true")
    private String name;

    @Name
    @Persistent(defaultFetchGroup = "true")
    private String surname;

    @Persistent(defaultFetchGroup = "true")
    private Date dateOfBirth;

    @Persistent(defaultFetchGroup = "true")
    private Date dateRecorded;

    @Persistent(defaultFetchGroup = "true")
    private String locationId;

    @Persistent(embedded = "true", defaultFetchGroup = "true")
    private CustomLocation customLocation;

    @Persistent(defaultFetchGroup = "true")
    private Category category;

    @Persistent(embedded = "true", defaultFetchGroup = "true")
    private CustomCategory customCategory;

    @Persistent(defaultFetchGroup = "true")
    private String description;

    @Persistent(embeddedElement = "true", defaultFetchGroup = "true")
    private List<StoredImageInfo> images;

    @Persistent(embeddedElement = "true", defaultFetchGroup = "true")
    private List<StoredAudioInfo> audio;

    @Persistent(embeddedElement = "true", defaultFetchGroup = "true")
    private List<StoredFileInfo> files;

    @Persistent(defaultFetchGroup = "true")
    private ModerationMode moderationMode;

    @Persistent(defaultFetchGroup = "true")
    private VisibilityMode visibilityMode;

    @Persistent(embedded = "true", defaultFetchGroup = "true")
    private UserProfileSummary owner;

    @Persistent(embeddedElement = "true", defaultFetchGroup = "true")
    private Map<String, UserProfileSummary> editors;

    @Persistent(embeddedElement = "true", defaultFetchGroup = "true")
    private Map<String, UserProfileSummary> connections;

    @Persistent(embeddedElement = "true", defaultFetchGroup = "true")
    private Map<String, RecordSummary> recordConnections;

    @Persistent(defaultFetchGroup = "true")
    private RecordType type;

    @Persistent(defaultFetchGroup = "true")
    private Date expiry;

    public Record() {
    }

    public Record(Record copy) {
        deepCopy(copy);
    }

    ...
}


@PersistenceCapable(embeddedOnly = "true")
public class RecordSummary implements Serializable {

    private static final long serialVersionUID = 9024309306966814904L;

    @Persistent(defaultFetchGroup = "true")
    private String id;

    @Persistent(defaultFetchGroup = "true")
    private RecordRole role;

    @Persistent(defaultFetchGroup = "true")
    private String name;

    @Persistent(defaultFetchGroup = "true")
    private String surname;

    @Persistent(defaultFetchGroup = "true")
    private Date dateOfBirth;

    @Persistent(defaultFetchGroup = "true")
    private Date dateRecorded;

    @SuppressWarnings("unused")
    private RecordSummary() {
        // for serialization
    }

    ...
}


@PersistenceCapable(detachable = "true")
public class Comment implements Attachable<String>, Serializable {

    private static final long serialVersionUID = -7624377549524333808L;

    @PrimaryKey
    @Persistent(defaultFetchGroup = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
    private String id;

    @Persistent(defaultFetchGroup = "true")
    private String recordId;

    @Persistent(defaultFetchGroup = "true")
    private String username;

    @Persistent(defaultFetchGroup = "true")
    private Date date;

    @Persistent(defaultFetchGroup = "true")
    private String content;

    @SuppressWarnings("unused")
    private Comment() {
        // for serialization
    }

    ...
}

I am not getting any such Exceptions with datanucleus enhancer 3.0-release (albeit, having other problems with 3.0: problem 1, problem 2). Is this a bug with DataNucleus 3.1 or am I doing something wrong?

UPDATE: DataNucleus Enhancer throws a NullPointerException for all List fields marked with @Persistent(embeddedElement = "true"). It is highly likely that this is a bug with the DataNucleus 3.1 Enhancer.

UPDATE 2: Upon request, I am including minimal code that reproduces the problem:

@PersistenceCapable(detachable = "true")
public class Record {

    @PrimaryKey
    @Persistent(defaultFetchGroup = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
    private String id;

    @Persistent(embeddedElement = "true", defaultFetchGroup = "true")
    private List<MyEmbeddedElement> aList;

    public Record() {
    }

}


@PersistenceCapable(embeddedOnly = "true")
public class MyEmbeddedElement {

    @Persistent
    private String myField;

}

The error:

 730  [main] DEBUG DataNucleus.MetaData  - Class "com.myproject.domain.Record" has been specified with JDO annotations so using those.
 760  [main] DEBUG DataNucleus.MetaData  - Class "com.myproject.domain.MyEmbeddedElement" has been specified with JDO annotations so using those.
 Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
763  [main] ERROR DataNucleus.Enhancer  - DataNucleus Enhancer completed with an error. Please review the enhancer log for full details. Some classes may have been enhanced but some caused errors
 Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
org.datanucleus.exceptions.NucleusUserException: Errors were encountered when loading the specified MetaData files and classes. See the nested exceptions for details
    at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:536)
    at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:734)
    at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:525)
    at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1258)
Caused by: java.lang.NullPointerException
    at org.datanucleus.api.jdo.metadata.JDOAnnotationReader.processMemberAnnotations(JDOAnnotationReader.java:1682)
    at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getMetaDataForClass(AbstractAnnotationReader.java:206)
    at org.datanucleus.metadata.annotations.AnnotationManagerImpl.getMetaDataForClass(AnnotationManagerImpl.java:171)
    at org.datanucleus.metadata.MetaDataManager.loadAnnotationsForClass(MetaDataManager.java:2650)
    at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:496)
    ... 3 more
Nested Throwables StackTrace:
java.lang.NullPointerException
    at org.datanucleus.api.jdo.metadata.JDOAnnotationReader.processMemberAnnotations(JDOAnnotationReader.java:1682)
    at org.datanucleus.metadata.annotations.AbstractAnnotationReader.getMetaDataForClass(AbstractAnnotationReader.java:206)
    at org.datanucleus.metadata.annotations.AnnotationManagerImpl.getMetaDataForClass(AnnotationManagerImpl.java:171)
    at org.datanucleus.metadata.MetaDataManager.loadAnnotationsForClass(MetaDataManager.java:2650)
    at org.datanucleus.metadata.MetaDataManager.loadClasses(MetaDataManager.java:496)
    at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:734)
    at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:525)
    at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1258)
DataNucleus Enhancer completed with an error. Please review the enhancer log for full details. Some classes may have been enhanced but some caused errors

UPDATE 3: This problem exists in all DataNucleus releases starting with 3.0.2.

1条回答
做自己的国王
2楼-- · 2019-02-25 14:27

When I do an embedded collection in my app I do

@Element(embedded="true")
Collection<OtherType> myCollField;

and that works for me, and looks more logical way of specifying embedded elements.

Also your map fields are wrong ... a map has no "element", it has "key" and "value"

查看更多
登录 后发表回答