Skip to content

Commit 8a567b3

Browse files
Fix NPE in InPlaceEditView.reLayoutEdit (#4235)
* Fix NPE in InPlaceEditView.reLayoutEdit InPlaceEditView.reLayoutEdit accesses sInstance.impl within a Runnable posted to callSerially. If sInstance is cleared (e.g. by stopEdit) before this Runnable executes or inside it, sInstance.impl can throw a NPE or crash if sInstance is null. This change captures sInstance to a local variable and checks for nullity before accessing its members. Also added a reproduction test case in HelloCodenameOneInstrumentedTest.java. * Fix NPE in InPlaceEditView.reLayoutEdit and add reproduction test InPlaceEditView.reLayoutEdit accesses sInstance.impl within a Runnable posted to callSerially. If sInstance is cleared (e.g. by stopEdit) before this Runnable executes or inside it, sInstance.impl can throw a NPE. This change captures sInstance to a local variable and checks for nullity before accessing its members. Also added a reproduction test case in scripts/hellocodenameone using a NativeInterface to reproduce the race condition on Android. Deleted unused dead code HelloCodenameOneInstrumentedTest.java. * Fix NPE in InPlaceEditView.reLayoutEdit and add reproduction test InPlaceEditView.reLayoutEdit accesses sInstance.impl within a Runnable posted to callSerially. If sInstance is cleared (e.g. by stopEdit) before this Runnable executes or inside it, sInstance.impl can throw a NPE. This change captures sInstance to a local variable and checks for nullity before accessing its members. Also added a reproduction test case in scripts/hellocodenameone using a NativeInterface to reproduce the race condition on Android. Deleted unused dead code HelloCodenameOneInstrumentedTest.java. Added iOS stub for the reproduction test. Updated test to avoid blocking EDT during wait. * Fix NPE in InPlaceEditView.reLayoutEdit and add reproduction test InPlaceEditView.reLayoutEdit accesses sInstance.impl within a Runnable posted to callSerially. If sInstance is cleared (e.g. by stopEdit) before this Runnable executes or inside it, sInstance.impl can throw a NPE. This change captures sInstance to a local variable and checks for nullity before accessing its members. Also added a reproduction test case in scripts/hellocodenameone using a NativeInterface to reproduce the race condition on Android. Deleted unused dead code HelloCodenameOneInstrumentedTest.java. Added iOS stub (ObjC) for the reproduction test to avoid compilation errors. Updated test to avoid blocking EDT during wait. * Restore iOS Java stub for InPlaceEditViewNativeImpl Restored scripts/hellocodenameone/ios/src/main/java/com/codenameone/examples/hellocodenameone/InPlaceEditViewNativeImpl.java which is required for NativeLookup on iOS, complementing the Objective-C implementation. Confirmed Android implementation exists. * Remove iOS implementation of InPlaceEditViewNativeImpl Removed the iOS Java stub and Objective-C implementation files. InPlaceEditViewNativeImpl should only exist in the Android subproject. On iOS, NativeLookup will simply not find the implementation, which is the desired behavior (skipping the test). This also avoids compilation issues related to missing native headers on iOS when the Java class is present. * Refactor InPlaceEditViewTest to use callback and adapt harness Updated InPlaceEditViewNativeImpl (Android) to use direct imports (removing reflection) and a callback for result reporting. Added ReproductionCallback interface. Updated iOS stub and ObjC files to match the new signature. Adapted BaseTest and Cn1ssDeviceRunner to support explicit test failure reporting and screenshot status logging. InPlaceEditViewTest now waits for the callback and fails if an error occurs during reproduction. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 2e316af commit 8a567b3

File tree

11 files changed

+182
-385
lines changed

11 files changed

+182
-385
lines changed

Ports/Android/src/com/codename1/impl/android/InPlaceEditView.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,8 +1540,10 @@ public void run() {
15401540
final int h = lastTextAreaHeight = txt.getHeight();
15411541

15421542

1543-
sInstance.impl.getActivity().runOnUiThread(new Runnable() {
1544-
public void run() {
1543+
final InPlaceEditView instance = sInstance;
1544+
if (instance != null) {
1545+
instance.impl.getActivity().runOnUiThread(new Runnable() {
1546+
public void run() {
15451547
if (mIsEditing && !isActiveTextEditorHidden() && sInstance != null && sInstance.mEditText != null) {
15461548

15471549
if (sInstance.mEditText.mTextArea != txt) {
@@ -1572,6 +1574,7 @@ public void run() {
15721574
}
15731575
}
15741576
});
1577+
}
15751578
}
15761579
}
15771580
}

0 commit comments

Comments
 (0)