You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "ks8219 (via GitHub)" <gi...@apache.org> on 2026/09/29 19:36:50 UTC

Re: [I] NullPointerException after several successive float/dock operations [netbeans]

ks8219 commented on issue #9422:
URL: https://github.com/apache/netbeans/issues/9422#issuecomment-5897287910

   Finally getting back to this.  I agree, it would be good to provide a contribution.  At the moment, however (and much as I would like to), I'm not really set up to submit an actual PR.  So will need to just report this particular issue, and merely suggest a possible fix.
   
   As I indicated in my original description, the issue occurs in the `getModeTopComponentPreviousIndex()` method of `DefaultModel`.
   
   The current code is the following...
   
   ```
       @Override
       public int getModeTopComponentPreviousIndex(ModeImpl mode, String tcID) {
           ModeModel modeModel = getModelForMode(mode);
           return modeModel == null ? null : modeModel.getTopComponentPreviousIndex(tcID);
       }
   ```
   
   The presence of `null` in the return statement (I think) indicates to the compiler to interpret the statement as returning an `Integer`.  If the `modeModel` evaluates to `null`, the statement tries to return a `null` `Integer`, and this is what causes the un-boxing to fail when the method tries to return an `int` primitive.
   
   The solution that I've implemented for our code is simply to change the 'true' part of the return statement such that it evaluates to -1, rather than `null`...
   
   ```
       @Override
       public int getModeTopComponentPreviousIndex(ModeImpl mode, String tcID) {
           ModeModel modeModel = getModelForMode(mode);
           return modeModel == null ? -1 : modeModel.getTopComponentPreviousIndex(tcID);
       }
   ```
   
   This prevents the compiler from interpreting the statement as evaluating to an `Integer`.  I'm not sure if the -1 value is the correct value, but it appears to be consistent with other parts of the code.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists