Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite-java - Parser issue with consecutive comment blocks #4344

Closed
nmck257 opened this issue Jul 19, 2024 · 1 comment · Fixed by #4624
Closed

rewrite-java - Parser issue with consecutive comment blocks #4344

nmck257 opened this issue Jul 19, 2024 · 1 comment · Fixed by #4624
Assignees
Labels
bug Something isn't working parser-java

Comments

@nmck257
Copy link
Collaborator

nmck257 commented Jul 19, 2024

Test case:

    @Test
    void consecutiveCommentBlocks() {
        rewriteRun(
          java(
            """
            package org.sample;

            //import org.apache.log4j.Logger;
            /*import org.apache.logging.log4j.LogManager;
            import org.apache.logging.log4j.Logger;*/
            
            /**
             * Does stuff
             */
            public class MyClass {
            /*//	private static Logger log = Logger.getLogger(MyClass.class);
                private static Logger log = (Logger) LogManager.getLogger(MyClass.class);
                *//**
                 * Does main stuff
                 *
                 * @param arguments
                 *//*
                public static void main(String[] args) {
                }
                *//*public static void main(String[] arguments) {
                    
                }*/
            }
            """
          )
        );
    }

Result:

org.opentest4j.AssertionFailedError: [When parsing and printing the source code back to text without modifications, the printed source didn't match the original source code. This means there is a bug in the parser implementation itself. Please open an issue to report this, providing a sample of the code that generated this error for "org\sample\MyClass.java":
diff --git a/org/sample/MyClass.java b/org/sample/MyClass.java
index 01d13a3..f0e4660 100644
--- a/org/sample/MyClass.java
+++ b/org/sample/MyClass.java
@@ -14,10 +14,10 @@ 
      * Does main stuff
      *
      * @param arguments
-     *//*
+     *////
     public static void main(String[] args) {
     }
-    *//*public static void main(String[] arguments) {
+    //*public static void main(String[] arguments) {
 
-    }*/
-}
\ No newline at end of file
+    }/
+}//*
\ No newline at end of file
] 
expected: "package org.sample;

//import org.apache.log4j.Logger;
/*import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;*/

/**
 * Does stuff
 */
public class MyClass {
/*//	private static Logger log = Logger.getLogger(MyClass.class);
    private static Logger log = (Logger) LogManager.getLogger(MyClass.class);
    *//**
     * Does main stuff
     *
     * @param arguments
     *//*
    public static void main(String[] args) {
    }
    *//*public static void main(String[] arguments) {

    }*/
}"
 but was: "package org.sample;

//import org.apache.log4j.Logger;
/*import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;*/

/**
 * Does stuff
 */
public class MyClass {
/*//	private static Logger log = Logger.getLogger(MyClass.class);
    private static Logger log = (Logger) LogManager.getLogger(MyClass.class);
    *//**
     * Does main stuff
     *
     * @param arguments
     *////
    public static void main(String[] args) {
    }
    //*public static void main(String[] arguments) {

    }/
}//*"
	at org.openrewrite.test.RewriteTest.assertContentEquals(RewriteTest.java:616)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:311)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:132)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:127)
	at org.openrewrite.java.JavaParserTest.consecutiveCommentBlocks(JavaParserTest.java:59)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
@nmck257 nmck257 added the bug Something isn't working label Jul 19, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Jul 22, 2024
@timtebeek
Copy link
Contributor

@nmck257 You'll be interested to see

Any help with review & testing this out appreciated, but not necessary of course.

@timtebeek timtebeek moved this from Backlog to In Progress in OpenRewrite Oct 29, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser-java
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants