netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

refactor rename record field does partial change and syntax error, or NPE

Open errael opened this issue 2 years ago • 2 comments

Apache NetBeans version

Apache NetBeans latest daily build

What happened

Refactor field name in record declaration, got syntax error in file. Similar situation produces an NPE, see below.

How to reproduce

In the following source code, with the caret on the field named string in the record `ClipData, refactor rename. The field name gets changed where it's referenced, but not in the record declaration.

public class Library {
    public void someLibraryMethod() {
	int type;
	String stringData;
	var clipData = getClipData(); 
	type = clipData.type;
	stringData = clipData.string; /////// this gets changed to stringData
    }
//////////////////////////////////// VVVVVV ///// refactor this to stringData
    record ClipData(int type, String string) {}
    private ClipData getClipData() {
	return new ClipData(3, "foo");
    }
}

Interestingly, if the field reference is the function, like

stringData = clipData.string()

Then nothing is changed, the refactor fails, but the file is not left with a syntax error.

If the caret is on string() then there is an NPE.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Linux harmony 5.19.0-76051900-generic #202207312230~1660780566~22.04~9d60db1

JDK

openjdk version "11.0.2" 2019-01-15

Apache NetBeans packaging

Own source build

Anything else

No response

Are you willing to submit a pull request?

No

Code of Conduct

Yes

errael avatar Oct 03 '22 00:10 errael

The SourceLevel is 19.

errael avatar Oct 03 '22 00:10 errael

yeah this is likely related to #4257, the editor thinks those are not the same fields (since its both a parameter and a field) for some reason - if you rename one, the other isn't renamed.

You can see this already by putting the cursor over the field. It doesn't highlight the other one.

mbien avatar Oct 03 '22 02:10 mbien