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

Failure to write out type table for nested types in hibernate-core:6.5.1.Final #4993

Open
timtebeek opened this issue Feb 6, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@timtebeek
Copy link
Contributor

What version of OpenRewrite are you using?

I am using

  • OpenRewrite 8.45.0-SNAPSHOT

How are you running OpenRewrite?

I'm running ./gradlew createTypeTable against openrewrite/rewrite-hibernate through a locally installed version of this build plugin

What is the smallest, simplest way to reproduce the problem?

  1. Checkout this branch Add task to create type tables to replace resource jars rewrite-build-gradle-plugin#75
  2. Run ./gradlew pTML on said branch
  3. Checkout openrewrite/rewrite-hibernate
  4. Change settings.gradle.kts to add
pluginManagement {
    repositories {
        mavenLocal()
        gradlePluginPortal()
    }
}
  1. Change build.gradle.kts to use recipe-library version latest.integration
  2. Run ./gradlew createTypeTable
  3. Delete src/main/resources/META-INF/rewrite/classpath
  4. Run the unit tests

What did you expect to see?

A successfully created type table used to pass the unit tests.

What did you see instead?

A failure to run the unit tests

What is the full stack trace of any errors you encountered?

java.lang.IllegalArgumentException: Invalid access flags: 32

	at org.objectweb.asm.util.CheckClassAdapter.checkAccess(CheckClassAdapter.java:542)
	at org.objectweb.asm.util.CheckClassAdapter.visitInnerClass(CheckClassAdapter.java:363)
	at org.openrewrite.java.internal.parser.TypeTable$Reader.lambda$writeClassesDir$3(TypeTable.java:207)
	at java.base/java.util.HashMap.forEach(HashMap.java:1421)
	at org.openrewrite.java.internal.parser.TypeTable$Reader.writeClassesDir(TypeTable.java:180)
	at org.openrewrite.java.internal.parser.TypeTable$Reader.read(TypeTable.java:169)
	at org.openrewrite.java.internal.parser.TypeTable.<init>(TypeTable.java:97)
	at org.openrewrite.java.internal.parser.TypeTable.fromClasspath(TypeTable.java:89)
	at org.openrewrite.java.JavaParser.dependenciesFromResources(JavaParser.java:130)
	at org.openrewrite.java.JavaParser$Builder.classpathFromResources(JavaParser.java:331)
	at org.openrewrite.hibernate.MigrateUserTypeTest.defaults(MigrateUserTypeTest.java:33)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:137)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:129)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:124)
	at org.openrewrite.hibernate.MigrateUserTypeTest.shouldMigrateUserType(MigrateUserTypeTest.java:41)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

When attempting to write out these values with ASM.
Image

@timtebeek
Copy link
Contributor Author

Notice above how the outerName has no relation to the class being written; I suppose we need to change these lines

for (ClassDefinition innerClass : innerClasses) {
classWriter.visitInnerClass(
innerClass.getName(),
classDef.getName(),
innerClass.getName().substring(innerClass.getName().lastIndexOf('$') + 1),
innerClass.getAccess()
);
}

to

                for (ClassDefinition innerClass : innerClasses) {
                    int lastIndexOf$ = innerClass.getName().lastIndexOf('$');
                    classWriter.visitInnerClass(
                            innerClass.getName(),
                            innerClass.getName().substring(0, lastIndexOf$),
                            innerClass.getName().substring(lastIndexOf$ + 1),
                            innerClass.getAccess()
                    );
                }

but even then we see the same access issues in org.objectweb.asm.util.CheckClassAdapter#checkAccess.

@jkschneider
Copy link
Member

@timtebeek I think it may be sufficient to just bitwise NOT out the flags that shouldn't be written in this case.

@timtebeek
Copy link
Contributor Author

There's a few more issues it seems; the tests were running without validation

@timtebeek timtebeek moved this to In Progress in OpenRewrite Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

No branches or pull requests

2 participants