Giter Site home page Giter Site logo

Comments (7)

timtebeek avatar timtebeek commented on June 2, 2024

Hi @ylemoigne ; thanks for trying out the latest version released today before reporting your issue here; really appreciated!

I'm looking at the stacktrace and the associated class, but I'm not seeing any recent changes there that might factor in:
https://github.com/openrewrite/rewrite/commits/v8.11.2/rewrite-java/src/main/java/org/openrewrite/java/format/TabsAndIndentsVisitor.java

A couple of questions as I don't yet have enough of a lead to troubleshoot this.

  • Is there any indication of what file it stumbles over?
  • Would you be able to share part of that file with us?
  • Is there any style configuration on your part that might factor in?
  • And what recipe did you run to trigger this?

from rewrite.

ylemoigne avatar ylemoigne commented on June 2, 2024

Hi @timtebeek

Yes there is an indication of what is the java source file but sadly, I'm not able to share it with anyone (legal stuff).

No style, here the whole config I'm using :

rewrite {
    activeRecipe("org.openrewrite.java.RemoveUnusedImports")
    activeRecipe("org.openrewrite.java.OrderImports")
}

I know that without the file that raise this issue it's hard to debug for you, I'm sorry.

from rewrite.

timtebeek avatar timtebeek commented on June 2, 2024

Not having access to that file sure makes it a challenge indeed to know if this has been solved somewhere down the line.

Would you be able to on your own machine (only) create a unit test for either of those recipes containing your class?

You can place that test either in OrderImportsTest

@Issue("https://github.com/openrewrite/rewrite/issues/259")
@Test
void multipleClassesWithTheSameNameButDifferentPackages() {
rewriteRun(
java(
"""
import java.awt.List;
import java.util.List;
class Test {}
"""
)
);
}

Or in RemoveUnusedImportsTest

@Test
void enumsFromInnerClass() {
rewriteRun(
java(
"""
package org.openrewrite;
public class Outer {
public enum E {
A, B, C, D
}
}
"""
),
java(
"""
import static org.openrewrite.Outer.E.*;
public class Test {
Object a = A;
Object b = B;
Object c = C;
}
"""
)
);
}

If that indeed reproduces the issue for you, then you can gradually strip away as much as possible, until there's a minimum left to replicate the issue in a manner you can hopefully share. Any help there would be appreciated, as we'd like to see this resolved for you, but our options are limited without that access to the failed file.

from rewrite.

ylemoigne avatar ylemoigne commented on June 2, 2024

I'm not sure how it works.

If I try to replace the string in multipleClassesWithTheSameNameButDifferentPackages to

java(
            """
              package foo;
              
              public class Toto extends Foo {
              }
              """
          )

The test already fail.

java.lang.IllegalStateException: LST contains missing or invalid type information
Identifier->ClassDeclaration->CompilationUnit
/*~~(Identifier type is missing or malformed)~~>*/Foo
	at org.openrewrite.java.Assertions.assertValidTypes(Assertions.java:87)

It seems that it need to know all dependencies. If it's true, I don't know how to provide it. (And I hope that's not too hard, the source file causing issue is 1600 lines long and have a lot of dependend types 😅 )

from rewrite.

knutwannheden avatar knutwannheden commented on June 2, 2024

To fix that particular problem you can just disable all type validation like so:

spec -> spec.typeValidationOptions(TypeValidation.none()),

from rewrite.

timtebeek avatar timtebeek commented on June 2, 2024

Perhaps it helps to ignore type validation options for your recipe, although that would also affect the remove imports recipe.

 @Test 
 void foo() { 
     rewriteRun(
       spec -> spec.recipe(new RemoveUnusedImports()).typeValidationOptions(TypeValidation.none()),
       java( 
         """ 
           import java.awt.List; 
           import java.util.List; 
                          
           class Test {} 
           """ 
       ) 
     ); 
 }

from rewrite.

ylemoigne avatar ylemoigne commented on June 2, 2024

On my project, the minimal setup to have the exception is :

rewrite {
    activeRecipe("org.openrewrite.java.OrderImports")
}

So in OrderImportsTest, I wrote :

    @Issue("https://github.com/openrewrite/rewrite/issues/3821")
    @Test
    void unidenfiedIssue() {
        String content;
        try {
            content = Files.readString(
              Paths.get("/pathTo/Culprit.java"), // Culprit designated by "Error while visiting `theClassFullyQualifiedName`"
              StandardCharsets.UTF_8);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }

        rewriteRun(
          spec -> spec.typeValidationOptions(TypeValidation.none()),
          java(content)
        );
    }

The test run end with The recipe must not make changes to ...

I don't understand why it don't crash before in the the test.
I have checked out the v8.11.2 tag (commit: cba6919), I've run the test with the same JVM I use to build my projet (temurin 11)

I don't know how to go further :/

from rewrite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.