<div dir="ltr"><div dir="ltr"><div>Hi,</div><div><br></div><div>Ah, nice. I see.</div><div><br></div><div>OK, then the issue for the NPE is deeper in the setting of "undoChange".</div><div><br></div>In short:<br></div><div dir="ltr"><br></div><div dir="ltr">        TextField textField = new TextField();<br>        textField.setPromptText("Type something and then press Ctrl+Z.");<br>        vbox.getChildren().add(textField);<br>        SimpleStringProperty textProperty = new SimpleStringProperty();<br>        textProperty.addListener((_, _, newValue) -> textField.textProperty().set(newValue));<br>        textField.textProperty().addListener((_, _, newValue) -> textProperty.set(newValue));</div><div dir="ltr"><div><br></div><div>When typing something and then presses Ctrl+Z, the exception is:</div><div><br></div><div>Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot read field "next" because "this.undoChange" is null<br>        at javafx.controls@22.0.1/javafx.scene.control.TextInputControl.updateUndoRedoState(TextInputControl.java:1250)<br>        at javafx.controls@22.0.1/javafx.scene.control.TextInputControl.undo(TextInputControl.java:1201)<br>        at javafx.controls@22.0.1/com.sun.javafx.scene.control.behavior.TextInputControlBehavior.undo(TextInputControlBehavior.java:553)</div><div><br></div><div>I know that this minimal example is not a good code. a two-way bindings should be used there. However, we need this to re-position the cursor right if another thread modifies the text content. If we do not modify the cursor position, the cursor jumps to position 0. Our use case is to "reformat on save". This is also a feature of IntelliJ. For instance, imports are organized. If IntelliJ modifies the Java file, the cursor keeps its position relative in the text and does not move to the first column in the first line.</div><div><br></div><div>(Full example for compilation at <a href="https://github.com/Siedlerchr/javafxreproducer/pull/22">https://github.com/Siedlerchr/javafxreproducer/pull/22</a>)</div><div><br></div><div>Cheers,</div><div><br></div><div>Oliver<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am So., 7. Juli 2024 um 13:28 Uhr schrieb Johannes Riecken <<a href="mailto:johannes.riecken@gmail.com">johannes.riecken@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div> Hey Oliver</div><div><br></div><div>The Java compiler does in fact do some "smart" optimizations, which you can easily verify by writing a void function with an early return yourself, compiling it to a class file and decompiling the class file again :) In this case, I assume that having a single point of exit helps the compiler to analyze control flow.<br></div><div><br></div><div>Cheers</div><div><br></div><div>Johannes<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jul 7, 2024 at 9:45 AM Oliver Kopp <<a href="mailto:kopp.dev@gmail.com" target="_blank">kopp.dev@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Dear all,<br><br>I have a strange thing here in JavaFX - and I seek some guidance, what to do.<br><br>I am searching for the source code of javafx.scene.control.TextInputControl.TextProperty#doSet of "javafx-controls-21-win.jar".<br><br>Using a decompiler, the method reads as follows (shortended):<br><br><br>private void doSet(String var1) {<br>...<br>    if (TextInputControl.this.filterAndSet(var1)) {<br>...<br>        TextInputControl.this.textUpdated();<br>        TextInputControl.this.resetUndoRedoState();<br>    }<br>}<br><br><br>I checked the source on GitHub at <a href="https://github.com/openjdk/jfx/blob/72701e6cb4095b8f5042f54ae6bb2c0cec446bcf/modules/javafx.controls/src/main/java/javafx/scene/control/TextInputControl.java#L1511" target="_blank">https://github.com/openjdk/jfx/blob/72701e6cb4095b8f5042f54ae6bb2c0cec446bcf/modules/javafx.controls/src/main/java/javafx/scene/control/TextInputControl.java#L1511</a>:<br><br><br>private void doSet(String value) {<br>...<br>   if (!filterAndSet(value)) return;<br>...<br>        textUpdated();<br>...<br>   resetUndoRedoState();<br>}<br><br><br>I assume that the Java compiler does not do some "smart" optimizations. Thus, the binary is different from the source somehow.<br><br><br>Can someone explain me what is happening here? Why is the decompiled source different from the Java source?<br><br><br>TYIA and cheers,<br><br>Oliver<br></div>
</blockquote></div>
</blockquote></div></div>