jlahoda commented on a change in pull request #1071: [NETBEANS-1728] fix for 
Exception encountered when break returns value
URL: 
https://github.com/apache/incubator-netbeans/pull/1071#discussion_r247402265
 
 

 ##########
 File path: 
java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java
 ##########
 @@ -1355,7 +1355,11 @@ public StatementTree getBreakContinueTarget(TreePath 
breakOrContinue) throws Ill
         
         switch (leaf.getKind()) {
             case BREAK:
-                return (StatementTree) ((JCTree.JCBreak) leaf).target;
+                Tree breakTarget = (Tree) ((JCTree.JCBreak) leaf).target;
+                if (breakTarget == null || !(breakTarget instanceof 
StatementTree)) {
+                    return null;
 
 Review comment:
   So.... this may be OK (or the only possibility) for this method, but as this 
is inevitably behavioraly incompatible, what about the clients? As the report 
is about the NPE check hint, that hint will be at least slightly broken in 
presence of switch expressions, won't it be?
   
   For compatibility, I don't think we can avoid the behavioral incompatibility 
here, but then we could:
   a) add a new method that would return Tree and deprecate this one
   b) change the return type to Tree here, which is inevitably source 
incompatible. Binary compatibility might be preservable through bytecode 
patching.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
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