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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to