We're updating the issue view to help you get more done. 

5.2.14 regression: NullPointerException in AbstractPropertyMapping.getSuperCollection

Description

The following exception is thrown with hibernate-core 5.2.14:

1 2 3 4 5 6 7 8 Caused by: java.lang.NullPointerException: null at org.hibernate.persister.entity.AbstractPropertyMapping.getSuperCollection(AbstractPropertyMapping.java:285) at org.hibernate.persister.entity.AbstractPropertyMapping.addPropertyPath(AbstractPropertyMapping.java:198) at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:395) at org.hibernate.persister.entity.AbstractEntityPersister.initOrdinaryPropertyPaths(AbstractEntityPersister.java:2300) at org.hibernate.persister.entity.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:2347) at org.hibernate.persister.entity.AbstractEntityPersister.postConstruct(AbstractEntityPersister.java:3906) at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:563)

The code in question looks like this:

AbstractPropertyMapping.java

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 private Collection getSuperCollection(MetadataImplementor metadata, PersistentClass clazz1, PersistentClass commonPersistentClass, String propertyName) { Class<?> c1 = clazz1.getMappedClass(); Class<?> c2 = commonPersistentClass.getMappedClass(); MappedSuperclass commonMappedSuperclass = null; // First we traverse up the clazz2/commonPersistentClass super types until we find a common type while ( !c2.isAssignableFrom( c1 ) ) { if ( commonPersistentClass == null) { /* L285 */ if ( commonMappedSuperclass.getSuperPersistentClass() == null ) { commonMappedSuperclass = commonMappedSuperclass.getSuperMappedSuperclass(); commonPersistentClass = null; } else { commonPersistentClass = commonMappedSuperclass.getSuperPersistentClass(); commonMappedSuperclass = null; } } else { if ( commonPersistentClass.getSuperclass() == null ) { commonMappedSuperclass = commonPersistentClass.getSuperMappedSuperclass(); commonPersistentClass = null; } else { commonPersistentClass = commonPersistentClass.getSuperclass(); commonMappedSuperclass = null; } } } // Then we traverse it's types up as long as possible until we find a type that has a collection binding while ( c2 != Object.class ) { if ( commonMappedSuperclass != null ) { Collection collection = metadata.getCollectionBinding( commonMappedSuperclass.getMappedClass().getName() + "." + propertyName ); if ( collection != null ) { return collection; } if ( commonMappedSuperclass.getSuperPersistentClass() == null ) { commonMappedSuperclass = commonMappedSuperclass.getSuperMappedSuperclass(); commonPersistentClass = null; } else { commonPersistentClass = commonMappedSuperclass.getSuperPersistentClass(); commonMappedSuperclass = null; } } else { Collection collection = metadata.getCollectionBinding( commonPersistentClass.getEntityName() + "." + propertyName ); if ( collection != null ) { return collection; } if ( commonPersistentClass.getSuperclass() == null ) { commonMappedSuperclass = commonPersistentClass.getSuperMappedSuperclass(); commonPersistentClass = null; } else { commonPersistentClass = commonPersistentClass.getSuperclass(); commonMappedSuperclass = null; } } } return null; }

/* L285 */ marks the line causing the NullPointerException.

Be aware that these two while loops would loop forever in absence of this exception since the variables c1 and c2 are never reassigned and there are no break statements either.

Environment

Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T21:39:06+02:00)
Java version: 1.8.0_162, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/jre
Default locale: en_DE, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"

Status

Assignee

Christian Beikov

Reporter

Jörn Huxhorn

Fix versions

Labels

None

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.2.13

Components

Affects versions

5.2.14

Priority

Critical