java.lang.NullPointerException

Hibernate JIRA | Gábor Varga | 1 year ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    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: {code:none} java.lang.NullPointerException at com.example.model.MyTestEntity.$$_hibernate_write_myTestEmbeddable(MyTestEntity.java) at com.example.model.MyTestEntity.<init>(MyTestEntity.java:37) {code} The interesting code snippets in the bytecode enhanced entity are as follows: {code:java} 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) { // #1 if (this.myTestEmbeddable != null) { ((CompositeTracker)this.myTestEmbeddable).$$_hibernate_clearOwner("myTestEmbeddable"); } // #2 if (!EqualsHelper.areEqual((Object)this.myTestEmbeddable, (Object)myTestEmbeddable)) { this.$$_hibernate_trackChange("myTestEmbeddable"); } // #3 MyTestEmbeddable myTestEmbeddable2 = myTestEmbeddable; // #4 if (this.$$_hibernate_getInterceptor() != null) { myTestEmbeddable2 = (MyTestEmbeddable)this.$$_hibernate_getInterceptor().writeObject((Object)this, "myTestEmbeddable", (Object)this.myTestEmbeddable, (Object)myTestEmbeddable); } // #5 this.myTestEmbeddable = myTestEmbeddable2; // #6 Object var4_3 = null; // #7 ((CompositeTracker)this.myTestEmbeddable).$$_hibernate_setOwner("myTestEmbeddable", (CompositeOwner)this); // #8 this.$$_hibernate_trackChange("myTestEmbeddable"); } {code} 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}}|https://github.com/hibernate/hibernate-orm/blob/5.0.8/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/PersistentAttributesEnhancer.java#L449] 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: {code:xml} <configuration> <enableLazyInitialization>true</enableLazyInitialization> <enableDirtyTracking>true</enableDirtyTracking> <enableAssociationManagement>false</enableAssociationManagement> <enableExtendedEnhancement>false</enableExtendedEnhancement> </configuration> {code} The description above is valid for Hibernate 5.0.8, but the same {{NullPointerException}} occurs when using Hibernate 5.1.0.

    Hibernate JIRA | 1 year ago | Gábor Varga
    java.lang.NullPointerException
  2. 0

    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: {code:none} java.lang.NullPointerException at com.example.model.MyTestEntity.$$_hibernate_write_myTestEmbeddable(MyTestEntity.java) at com.example.model.MyTestEntity.<init>(MyTestEntity.java:37) {code} The interesting code snippets in the bytecode enhanced entity are as follows: {code:java} 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) { // #1 if (this.myTestEmbeddable != null) { ((CompositeTracker)this.myTestEmbeddable).$$_hibernate_clearOwner("myTestEmbeddable"); } // #2 if (!EqualsHelper.areEqual((Object)this.myTestEmbeddable, (Object)myTestEmbeddable)) { this.$$_hibernate_trackChange("myTestEmbeddable"); } // #3 MyTestEmbeddable myTestEmbeddable2 = myTestEmbeddable; // #4 if (this.$$_hibernate_getInterceptor() != null) { myTestEmbeddable2 = (MyTestEmbeddable)this.$$_hibernate_getInterceptor().writeObject((Object)this, "myTestEmbeddable", (Object)this.myTestEmbeddable, (Object)myTestEmbeddable); } // #5 this.myTestEmbeddable = myTestEmbeddable2; // #6 Object var4_3 = null; // #7 ((CompositeTracker)this.myTestEmbeddable).$$_hibernate_setOwner("myTestEmbeddable", (CompositeOwner)this); // #8 this.$$_hibernate_trackChange("myTestEmbeddable"); } {code} 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}}|https://github.com/hibernate/hibernate-orm/blob/5.0.8/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/PersistentAttributesEnhancer.java#L449] 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: {code:xml} <configuration> <enableLazyInitialization>true</enableLazyInitialization> <enableDirtyTracking>true</enableDirtyTracking> <enableAssociationManagement>false</enableAssociationManagement> <enableExtendedEnhancement>false</enableExtendedEnhancement> </configuration> {code} The description above is valid for Hibernate 5.0.8, but the same {{NullPointerException}} occurs when using Hibernate 5.1.0.

    Hibernate JIRA | 1 year ago | Gábor Varga
    java.lang.NullPointerException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at com.example.model.MyTestEntity.$$_hibernate_write_myTestEmbeddable()
    2. com.example.model
      MyTestEntity.<init>
      1. com.example.model.MyTestEntity.$$_hibernate_write_myTestEmbeddable(MyTestEntity.java)
      2. com.example.model.MyTestEntity.<init>(MyTestEntity.java:37)
      2 frames