apache / apache/netbeans

Copying/renaming a Java class results in broken syntax in some cases

Open
#9,563 0 comments 0 reactions 0 assignees View on GitHub
Java kind:bug needs:triage
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 31

### What happened

Copying or renaming a Java class results in broken syntax in certain cases, see the examples below.

The error appears to be related to the fact that the class name appears multiple times as type argument in the interface list.

### Language / Project Type / NetBeans Component

Java, Editor, Refactoring

### How to reproduce

Create the following Java interface in a non-default package:
```java
package org.example;

interface Example extends Comparable, Iterable, Cloneable { }
```
Refactor-copy or refactor-rename the interface within the same package. The result is:
```java
interface Example1 extends Comparable,Iterable, , Cloneable { }
```
Notice the extra comma (which breaks the syntax) and the missing space before "Iterable".

The analogous example with a class instead of an interface exhibits the same error.

Different variations of the faulty result happen with different spacing. For example, adding an extra space before "Iterable" results in (notice the "null"):
```java
interface Example1 extends Comparable,null Iterable, , Cloneable { }
```
Similarly, removing the space before "Iterable" results in:
```java
interface Example1 extends Comparable,nullIterable, , Cloneable { }
```
Likewise, if the original uses multiple lines:
```java
interface Example
extends
Comparable,
Iterable,
Cloneable
{ }
```
the result is:
```java
interface Example1
extends
Comparable,null
Iterable, ,
Cloneable
{ }
```

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Windows

### JDK

JDK 21

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

The issue doesn't appear to happen in the default package.

The issue already occurred in NetBeans 30.

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue in the Java Editor Refactoring component with the provided non-default-package interface, then compare refactor-copy and refactor-rename results across the spacing variations. Done means the renamed or copied class has valid syntax, preserves the type argument list, and does not add extra commas, missing spaces, or null text.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.