INRIA / INRIA/spoon

[Bug]: Illegal Java code is transformed

Open
#6,163 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

### Describe the bug

When entering illegal Java code, the result is usually transformed to a different (but still illegal) code. However, in some cases it get transformed / deleted.

### Source code you are trying to analyze/transform

```Java
0;
0++;
int a = 0++;
```

### MCVE

```Java
package my.spoon.code;

import spoon.Launcher;
import spoon.support.compiler.VirtualFile;

public class Main {
public static void main(String[] args) {
Launcher launcher = new Launcher();
launcher.addInputResource(new VirtualFile(
"""
package the.pkg.name;

class ClassName {
void methodName() {
0;
0++;
int a = 0++;
}
}
"""
));
System.out.println(launcher.buildModel().getAllTypes());
}
}
```

### Actual output

```Java
0 = the.pkg.name.$missing$; // <- `0;`
// <- `0++;`
int a = 0; // <- `int a = 0++;`
```

### Expected output

```Java
// The same output. Illegal code shouldn't get transformed
0;
0++;
int a = 0++;
```

### Spoon Version

11.2.0

### JVM Version

17

### What operating system are you using?

Windows 10

Contributor guide

Open the contributing guide

Research direction

Start with the Java MCVE in Main, using Launcher, VirtualFile, and buildModel() to reproduce the behavior on Spoon 11.2.0. Trace how the three illegal statements are represented during parsing and model construction, then verify that the resulting output preserves 0;, 0++;, and int a = 0++; without transforming or deleting them.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.