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

NoClassDefFoundError on test running after new class creation #1032

Closed
Undin opened this issue Jun 23, 2022 · 3 comments
Closed

NoClassDefFoundError on test running after new class creation #1032

Undin opened this issue Jun 23, 2022 · 3 comments
Assignees
Labels
Milestone

Comments

@Undin
Copy link
Contributor

Undin commented Jun 23, 2022

Describe the bug
After updating to gradle-intellij-plugin 1.6.0, I constantly faced with NoClassDefFoundError exception on test running after new class creation (including creation new lambda since it creates new anonymous class from JVM point of view).
1.7.0-SNAPSHOT version doesn't help so master doesn't contain the corresponding fix.

Using 1.5.3 version helps, but it breaks launching plugin with 2022.2 IDEs.
Test running after clean task helps as well, but it's too slow since it recompiles everything from scratch

I assume it's because of using com.intellij.util.lang.PathClassLoader as system classloader added to 1.6.0

Stacktrace example
com/jetbrains/edu/learning/EduDocumentListenerTest$test type in placeholder$r$1
java.lang.NoClassDefFoundError: com/jetbrains/edu/learning/EduDocumentListenerTest$test type in placeholder$r$1
	at com.jetbrains.edu.learning.EduDocumentListenerTest.test type in placeholder(EduDocumentListenerTest.kt:23)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at junit.framework.TestCase.runTest(TestCase.java:176)
	at com.intellij.testFramework.UsefulTestCase.lambda$runBare$11(UsefulTestCase.java:533)
	at com.intellij.testFramework.UsefulTestCase.lambda$wrapTestRunnable$13(UsefulTestCase.java:554)
	at com.intellij.testFramework.UsefulTestCase.runTestRunnable(UsefulTestCase.java:454)
	at com.intellij.testFramework.fixtures.BasePlatformTestCase.runTestRunnable(BasePlatformTestCase.java:106)
	at com.intellij.testFramework.UsefulTestCase.defaultRunBare(UsefulTestCase.java:470)
	at com.intellij.testFramework.UsefulTestCase.lambda$runBare$12(UsefulTestCase.java:541)
	at com.intellij.testFramework.EdtTestUtil.lambda$runInEdtAndWait$1(EdtTestUtil.java:40)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:303)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:393)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.ClassNotFoundException: com.jetbrains.edu.learning.EduDocumentListenerTest$test type in placeholder$r$1
	at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:215)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 27 more

To Reproduce

  • checkout arseniy/classloading-problem branch of EduTools plugin
  • run gradle clean
  • run com.jetbrains.edu.learning.EduDocumentListenerTest#test type in placeholder test. It should pass
  • uncomment these lines
  • run com.jetbrains.edu.learning.EduDocumentListenerTest#test type in placeholder test again

Expected behavior
Test passes without NoClassDefFoundError

Environment:

  • OS: macOS 12.3.1
  • Gradle IntelliJ Plugin Version: 1.7.0-SNAPSHOT
  • Gradle Version: 7.4
@Undin Undin added the bug label Jun 23, 2022
@hsz hsz added this to the next milestone Jun 23, 2022
@hsz hsz self-assigned this Jun 23, 2022
@nico-loeber
Copy link

I've got the same issue. I wasn't aware this is caused by the gradle-intellij-plugin.

@hsz
Copy link
Member

hsz commented Jun 24, 2022

The problem is caused because of the new PathClassLoader introduced for 221+.
When running the instrumentation, by default the classpath.index file is created next to the instrumented classes, however, it doesn't get updated with an incremental run. The previous classloader provided an option for disabling the creation of this file entirely, but now it's not possible.
As a workaround, I'm removing such a file every time the instrumentation task runs, so it gets recreated.

hsz added a commit that referenced this issue Jun 24, 2022
@hsz
Copy link
Member

hsz commented Jun 25, 2022

Fix is available in the latest snapshot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants