java.lang.NullPointerException

JDK Bug System | Webbug Group | 2 months ago
  1. 0

    FULL PRODUCT VERSION : java version "1.8.0_102" Java(TM) SE Runtime Environment (build 1.8.0_102-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows [Version 6.1.7601] A DESCRIPTION OF THE PROBLEM : The following program declares a string property and registers three change listeners. The first listener changes the value from within its listener implementation and thus initiating a recursive notification. If fireValueChangedEvent is invoked, then a lock flag is set which prevents that modifications of the list will not be in conflict with iterating over the collection. After this recursive notification the lock flag is cleared. The second listener removes itself on the second notification, and since the lock flag was cleared, the internal array of change listeners is changed, i.e. the third listener becomes the second and the last reference is set to null. But on this null reference (i.e. the last listener) the changed method is then invoked. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Execute the program added to this bug report. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - The program should not throw an exception and in the console you should see the following output: listener1 listener1 Listener 2 listener3 123$/123$ Listener 2 remove myself from StringProperty [value: 123$] listener3 123$/123$ ACTUAL - listener1 listener1 Listener 2 listener3 123$/123$ Listener 2 remove myself from StringProperty [value: 123$] Exception in thread "main" java.lang.NullPointerException at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:361) at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81) at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103) at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110) at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144) at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49) at javafx.beans.property.StringProperty.setValue(StringProperty.java:65) at patterns.observer.cycle.fx.ReentrantCalls.main(ReentrantCalls.java:39) ERROR MESSAGES/STACK TRACES THAT OCCUR : lException in thread "main" java.lang.NullPointerException at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:361) at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81) at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103) at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110) at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144) at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49) at javafx.beans.property.StringProperty.setValue(StringProperty.java:65) at patterns.observer.cycle.fx.ReentrantCalls.main(ReentrantCalls.java:39) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public class ReentrantCalls { public static void main(String[] args) { StringProperty prop = new SimpleStringProperty("prop"); prop.addListener((observable, oldValue, newValue) -> { System.out.println("listener1"); if(newValue.length() % 2 ==1) prop.set(newValue + "$"); }); class OnceListener implements ChangeListener<String> { private int counter; public OnceListener(int value) { counter = value; } @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println("Listener 2"); if (--counter == 0) { System.out.println("remove myself from " + observable); observable.removeListener(this); } } } prop.addListener(new OnceListener(2)); prop.addListener((observable, oldValue, newValue) -> { System.out.println("listener3 "+newValue + "/" + prop.getValue()); }); prop.setValue("123"); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : The fix would be to replace the boolean flag by an integer value and increment/decrement that value and only allow to change the list of listeners if this value is 0.

    JDK Bug System | 2 months ago | Webbug Group
    java.lang.NullPointerException
  2. 0

    Java: SetText inside a thread

    Stack Overflow | 2 years ago | PicoYou
    java.lang.NullPointerException
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    JavaFX Programmatic POJO Expression Bindings (Part III) | UGate

    wordpress.com | 1 year ago
    java.lang.IllegalArgumentException: Unable to set object value: 929 on numero
  5. 0

    HtmlEditor loadSkinClass Failed to load skin

    Oracle Community | 5 years ago | 903307
    java.lang.NullPointerException

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent()
    2. com.sun.javafx
      ExpressionHelper.fireValueChangedEvent
      1. com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:361)
      2. com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
      2 frames
    3. javafx.beans.property
      StringProperty.setValue
      1. javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:103)
      2. javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:110)
      3. javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
      4. javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
      5. javafx.beans.property.StringProperty.setValue(StringProperty.java:65)
      5 frames
    4. patterns.observer.cycle
      ReentrantCalls.main
      1. patterns.observer.cycle.fx.ReentrantCalls.main(ReentrantCalls.java:39)
      1 frame