NullPointerException after several successive float/dock operations
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Apache NetBeans version
Apache NetBeans 30
### What happened
We're using the Netbeans/OpenIDE platform as the underlying framework for our application, STAR-CCM+. Some time ago, one of our testing engineers ran across an issue in which an embedded window is floated and docked several times. See attached screen recording.
https://github.com/user-attachments/assets/7bc4538d-5448-4e57-8b8e-c0fa2017a124
From the stack trace (see attached), one can see that the problem originates in the `getModeTopComponentPreviousIndex()` method defined in the **DefaultModel** class (part of the _org.netbeans.core.windows.model_ package).
[StackTrace.txt](https://github.com/user-attachments/files/28480474/StackTrace.txt)
Looking at the source code...
```
/** Gets the tab index of the given top component before it was moved to sliding/separate mode */
@Override
public int getModeTopComponentPreviousIndex(ModeImpl mode, String tcID) {
ModeModel modeModel = getModelForMode(mode);
return modeModel == null ? null : modeModel.getTopComponentPreviousIndex(tcID);
}
```
... it is possible that the `modeModel` variable can be `null`, and the `return` statement tries to accommodate for this possibility; however, in this case it tries to return a value `null` from the method. The compiler appears to allocate an `Integer` variable for this, then unboxes into an `int`. But the problem is that the value in the `Integer` is `null`, and the call to `Integer::intValue()` fails.
### Language / Project Type / NetBeans Component
Netbeans/OpenIDE platform
### How to reproduce
I can reproduce this in our application; however, I do not have a stand-alone example external of our application that I can provide. (And, quite honestly, I'm not sure how to create a small demonstrable platform-based application, let alone one that will reliably reproduce the problem.)
I've tried reproducing in the Netbeans IDE, but as yet have not been able to do so. It is possible that our application exposes a situation that does not normally occur otherwise. Nevertheless, you can see the reproduction from the attached video, and you can see in the code for `DefaultModel` where and under condition it occurs.
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
We've seen this in Windows 10 and Linux CentOS 7.9. Have not tried under later versions.
### JDK
Originally observed using JDK 17
### Apache NetBeans packaging
Apache NetBeans platform
### Anything else
I've been able to mitigate this for our application by adjusting our own copy of the platform code such that it returns a value -1 rather than `null`, so this does not seem to be an issue for us any longer. However, as far as I can tell in GitHub, the code in which the runtime could try to unbox a `null` `Integer` still exists, whether or not it will actually be exercised in a real application.
I'm not sure off-hand what a 'correct' value should be returned from the method if the `modeModel` is `null`, or perhaps whether it might be more appropriate to adjust the return type on the method to `Integer`, thus avoiding the unboxing operation.
In any event, I thought I should bring this to your attention.
### Are you willing to submit a pull request?
No
Contributor guide
Research direction
Start with DefaultModel.getModeTopComponentPreviousIndex() in the org.netbeans.core.windows.model package and review the attached stack trace and its callers. Determine the expected result when getModelForMode(mode) returns null, then use the supplied float/dock sequence or the reporter's application to verify that repeated operations no longer produce a NullPointerException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- desktop-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100