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.

Bug 164801

Summary: introduce variable does not work properly with new operator
Product: java Reporter: vity <vity>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED WONTFIX    
Severity: blocker CC: tprochazka
Priority: P4    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description vity 2009-05-08 20:59:42 UTC
Introduce variable does not work properly in this case:
To reproduce this bug:
1. Write this code (new keyword is important):
 someExpression;
 new MyClass.myMethod();
2. Select |someExpression|, call function Introduce variable

You get this wrong result:
        newfinal ExpressionDataType variableName = someExpression;
 MyClass.myMethod();

Expected result:
 final ExpressionDataType variableName = someExpression;
 new MyClass.myMethod();


Reproducable both 6.7b and 6.5.1.
Comment 1 Jiri Prox 2009-05-11 10:43:28 UTC
Can you please attach specific example?
thanks
Comment 2 vity 2009-05-11 10:51:06 UTC
Why this bug was moved into "hints" subcomponent? It's refactoring bug...

>>Can you please attach specific example?
Dummy example:

"hello"
new String("bug").getBytes();
Comment 3 Jiri Prox 2009-05-11 11:05:27 UTC
Thanks for example
The introduce variable is implemented in java/hint module, even it is located in Refactor menu, that's why the issue was
moved.

The code contains error before refactoring, so the AST is broken and the code is not updated correctly. If there is ';'
behind the expression, the code is generated correctly. -> downgrading to P4
Comment 4 tprochazka 2009-05-12 05:20:36 UTC
I think that this is very annoying bug, because I must write ';' at the end of line a then select whole line without 
';' and then use 'Introduce variable'. I think that with ';' is not necessary selection, NB can automatically select 
all between ';'.

Another smaller problem is that netbeans remove empty line before selected statement during this refactoring.
Comment 5 Martin Balin 2016-07-07 07:15:40 UTC
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