This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I'm working on a Java Project using Java 1.8.0. The refactoring feature 'Introduce Variable' sometimes doesn't work. With the following sample it works: int a = 2; int b = 2; System.out.println(a/b); If I want to introduce a new variable 'r', based on 'a/b', I get what I expect: int a = 2; int b = 2; int r = a/b; System.out.println(r); But when I add a multiplier before the division I get an error 'Invalid selection'. So I can't extract 'a/b': System.out.println(2 * a/b); However, when brackets are added around the division the refactoring works: System.out.println(2 * (a/b));
Not a P2 defect. Yes, it's a known issue, sadly. The reason is that the selection is (currently) implemented supposing that a region for a complete AST subtree is selected. This is the case of a/b selection. In 2 * a / b, the * associates left, so the expression is (in the tree form) actually (2 * a) / b; so a/b selection spans two branches of the AST treee, but not their common root -> invalid selection. It's unfortunate, since the internal form does not make sense to the user. The way how we work with selection must change.
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue. Thanks for your cooperation, NetBeans IDE 8.2 Release Boss