| When the in-line dirty tracking bytecode enhancement is enabled (the enableDirtyTracking parameter of the hibernate-enhance-maven-plugin's configuration is true), and an entity with an @Embeddable property is constructed by setting this field to null in the constructor, a NullPointerException is thrown from the following location:
java.lang.NullPointerException
at com.example.model.MyTestEntity.$$_hibernate_write_myTestEmbeddable(MyTestEntity.java)
at com.example.model.MyTestEntity.<init>(MyTestEntity.java:37)
The interesting code snippets in the bytecode enhanced entity are as follows:
private MyTestEmbeddable myTestEmbeddable;
@Transient
private transient PersistentAttributeInterceptor $$_hibernate_attributeInterceptor;
public MyTestEntity(Long id, Integer myTestInteger, MyTestEmbeddable myTestEmbeddable) {
this.$$_hibernate_write_id(id);
this.$$_hibernate_write_myTestInteger(myTestInteger);
this.$$_hibernate_write_myTestEmbeddable(myTestEmbeddable);
}
public PersistentAttributeInterceptor $$_hibernate_getInterceptor() {
return this.$$_hibernate_attributeInterceptor;
}
public void $$_hibernate_write_myTestEmbeddable(MyTestEmbeddable myTestEmbeddable) {
if (this.myTestEmbeddable != null) {
((CompositeTracker)this.myTestEmbeddable).$$_hibernate_clearOwner("myTestEmbeddable");
}
if (!EqualsHelper.areEqual((Object)this.myTestEmbeddable, (Object)myTestEmbeddable)) {
this.$$_hibernate_trackChange("myTestEmbeddable");
}
MyTestEmbeddable myTestEmbeddable2 = myTestEmbeddable;
if (this.$$_hibernate_getInterceptor() != null) {
myTestEmbeddable2 = (MyTestEmbeddable)this.$$_hibernate_getInterceptor().writeObject((Object)this, "myTestEmbeddable", (Object)this.myTestEmbeddable, (Object)myTestEmbeddable);
}
this.myTestEmbeddable = myTestEmbeddable2;
Object var4_3 = null;
((CompositeTracker)this.myTestEmbeddable).$$_hibernate_setOwner("myTestEmbeddable", (CompositeOwner)this);
this.$$_hibernate_trackChange("myTestEmbeddable");
}
The myTestEmbeddable argument of the constructor is null, so $$hibernate_write_myTestEmbeddable() is called with a null argument. The $$_hibernate_attributeInterceptor field is not initialized in the constructor, so $$_hibernate_getInterceptor() always returns null. Because of this, the conditional code _#4 is not run. In #3, the null argument is written to a temporary variable, and then in #5, it's written to the myTestEmbeddable field. Afterwards in #7, it's being cast to CompositeTracker, and its $$_hibernate_setOwner is called, while the field is still null. I think this is what throws the NullPointerException. The Java source files of the original and bytecode enhanced @Entity and @Embeddable classes are attached to this ticket. The hibernate-enhance-maven-plugin configuration was as follows:
<configuration>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>false</enableAssociationManagement>
<enableExtendedEnhancement>false</enableExtendedEnhancement>
</configuration>
|