Skip to content

[Bug]: Illegal Java code is transformed #6163

Open
@Clipi-12

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

0;
0++;
int a = 0++;

MCVE

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

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

Expected output

// 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions