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

[BUG] Launching JUnit test via editor window in Eclipse fails with NullPointerException #2985

Closed
Maia-Everett opened this issue Oct 6, 2021 · 9 comments · Fixed by #3007
Closed
Assignees
Milestone

Comments

@Maia-Everett
Copy link

Maia-Everett commented Oct 6, 2021

Describe the bug
When Lombok is installed, some actions, including trying to launch a JUnit test by right clicking the editor and selecting "Run -> JUnit Test", fail with a stack trace (see below).

However, the same test runs fine if launched via the Run toolbar command.

To Reproduce
I don't know how to reproduce this. It's an IDE problem with a large project, doesn't seem to be dependent on and I don't

Expected behavior
A clear and concise description of what you expected to happen.

Version info (please complete the following information):

  • Lombok version 1.18.20 and 1.18.21 edge (reproducible with both)
  • Platform: Eclipse 2020-12

Additional context

Stack trace:

java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:397)
	at org.eclipse.ui.internal.WorkbenchWindow.lambda$7(WorkbenchWindow.java:2353)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:74)
	at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2351)
	at org.eclipse.jdt.internal.junit.util.TestSearchEngine.findTests(TestSearchEngine.java:47)
	at org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut.findTypesToLaunch(JUnitLaunchShortcut.java:226)
	at org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut.findTypeToLaunch(JUnitLaunchShortcut.java:215)
	at org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut.launch(JUnitLaunchShortcut.java:191)
	at org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut.launch(JUnitLaunchShortcut.java:123)
	at org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension.launch(LaunchShortcutExtension.java:419)
	at org.eclipse.debug.internal.ui.actions.LaunchShortcutAction.runInternal(LaunchShortcutAction.java:83)
	at org.eclipse.debug.internal.ui.actions.LaunchShortcutAction.runWithEvent(LaunchShortcutAction.java:135)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:580)
	at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:414)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5785)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1427)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1453)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1436)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1225)
	at org.eclipse.jface.action.ActionContributionItem.lambda$8(ActionContributionItem.java:1209)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5785)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1427)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:5048)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4526)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1157)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	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 org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1461)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1434)
Caused by: java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.ASTNode.checkInvocationArguments(ASTNode.java:410)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:953)
	at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:390)
	at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:259)
	at org.eclipse.jdt.internal.compiler.ast.Block.resolve(Block.java:131)
	at org.eclipse.jdt.internal.compiler.ast.IfStatement.resolveIfStatement(IfStatement.java:282)
	at org.eclipse.jdt.internal.compiler.ast.IfStatement.resolve(IfStatement.java:308)
	at org.eclipse.jdt.internal.compiler.ast.Block.resolve(Block.java:131)
	at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.resolveType(LambdaExpression.java:458)
	at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.cachedResolvedCopy(LambdaExpression.java:975)
	at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.resolveExpressionExpecting(LambdaExpression.java:1005)
	at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.addConstraintsToC_OneExpr(InferenceContext18.java:681)
	at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.addConstraintsToC(InferenceContext18.java:649)
	at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.inferInvocationType(InferenceContext18.java:433)
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.computeCompatibleMethod18(ParameterizedGenericMethodBinding.java:271)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.isCompatibleWith(MessageSend.java:1100)
	at org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding.isCompatibleWith(PolyTypeBinding.java:43)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:5067)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:5031)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:871)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:798)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod0(Scope.java:1756)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod(Scope.java:1657)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getMethod(Scope.java:3045)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.findMethodBinding(MessageSend.java:1017)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:838)
	at org.eclipse.jdt.internal.compiler.ast.Expression.resolve(Expression.java:1113)
	at org.eclipse.jdt.internal.compiler.ast.Block.resolve(Block.java:131)
	at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.resolveType(LambdaExpression.java:458)
	at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolvePolyExpressionArguments(ASTNode.java:721)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.findMethodBinding(MessageSend.java:1024)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:838)
	at org.eclipse.jdt.internal.compiler.ast.Expression.resolve(Expression.java:1113)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:661)
	at org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration.resolveStatements(ConstructorDeclaration.java:673)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:570)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1493)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1618)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:662)
	at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.resolve(HierarchyResolver.java:875)
	at org.eclipse.jdt.internal.core.hierarchy.RegionBasedHierarchyBuilder.createTypeHierarchyBasedOnRegion(RegionBasedHierarchyBuilder.java:86)
	at org.eclipse.jdt.internal.core.hierarchy.RegionBasedHierarchyBuilder.build(RegionBasedHierarchyBuilder.java:55)
	at org.eclipse.jdt.internal.core.hierarchy.RegionBasedTypeHierarchy.compute(RegionBasedTypeHierarchy.java:79)
	at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.refresh(TypeHierarchy.java:1319)
	at org.eclipse.jdt.internal.core.CreateTypeHierarchyOperation.executeOperation(CreateTypeHierarchyOperation.java:94)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:740)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:806)
	at org.eclipse.jdt.core.JavaCore.newTypeHierarchy(JavaCore.java:5034)
	at org.eclipse.jdt.internal.junit.launcher.JUnit4TestFinder.findTestsInContainer(JUnit4TestFinder.java:130)
	at org.eclipse.jdt.internal.junit.util.TestSearchEngine.lambda$0(TestSearchEngine.java:42)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
@Rawi01
Copy link
Collaborator

Rawi01 commented Oct 6, 2021

Why do you think this is a lombok related problem? I have never noticed any JUnit problems in eclipse with lombok and I use it all the time. Without further details or a way to reproduce the problem it is almost impossible to fix it.

@rzwitserloot
Copy link
Collaborator

The stack trace could at least feasibly be a situation where lombok has left the AST in a state that causes NPEs later on. Not sure how in the blazes 'later on' ends up being 'when you attempt to... run a junit test?' - perhaps eclipse is trying to walk through the AST to find @Test-marked methods.

@Maia-Everett If there's any shot at all at making a recipe to reproduce this bug reliably, it's likely to be some specific lombok feature you're using in the file that you're right-clicking in. We'll need to know exactly which file is open, whether it is saved or not (I think running tests auto-saves), which on-save tasks you've enabled if any, and which version of lombok you're using (it's in eclipse's about menu; lombok throws a line in there with its version).

Without further feedback, this issue can be closed (due to having now feasible route forward to fix it) by 2021-10-24.

@rzwitserloot rzwitserloot added the parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these. label Oct 7, 2021
@Maia-Everett
Copy link
Author

Maia-Everett commented Oct 8, 2021

So I've taken a shot at making a minimal example. I verified that the issue reliably happens with that particular class, and that furthermore even a single syntax error introduced into the source makes Eclipse spit out an internal compiler error (with the same stack trace as above), and everything, including autocomplete, breaks.

The resulting file is very short:

package com.contoso.server.api.foobarsystem;

import com.contoso.dbo.QOrderHistory;
import com.contoso.server.persistence.IOrderHistoryRepository;

import lombok.val;

public class TestOrdersResource {
	private static IOrderHistoryRepository orderHistoryRepo;
	
	public TestOrdersResource() {
		val qoh = QOrderHistory.orderHistory;
		val history = orderHistoryRepo.findAll(qoh, qoh.order.eq(null));
	}
}

Unfortunately, when I moved the file to a new project, along with bare minimum surrounding code to get it to compile, the problem went away, and I'm not sure I can experiment with the entire (large) codebase by adding and removing files and code to see what causes the problem.

Nonetheless, I've attached that file along with minimal dependencies.

lombokbug2985.tar.gz

In the actual project, this code spits out the NPE I posted earlier, showing the internal error at the package level:
image

In the minimal project, the file simply doesn't compile, higlighting eq(null) as an overload ambiguity error (correctly). The original, full file did compile, but the internal compiler error was the same.

The example is truly minimal:

  • Replacing the second val with final OrderHistory makes the internal error go away. This is why I suspect it's Lombok related.
  • Resolving the overload ambiguity by replacing null with new Order() makes the code compile, and the internal compiler error goes away.
  • Replacing the second line with just val something = qoh.order.eq(null) makes it go away.

I suspect that since the minimal project doesn't reproduce the issue, it occurs when parsing one of the dependent files in their full (rather than just dummy classes and interfaces with stub implementations).

@Rawi01
Copy link
Collaborator

Rawi01 commented Oct 8, 2021

Thanks for sharing all this details. I will try to reproduce the problem using your example project.

As it is obviously related to val you can try to use the latest release as this replaces val with final var if you use Java >= 10.

@rzwitserloot rzwitserloot removed the parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these. label Oct 9, 2021
@Rawi01
Copy link
Collaborator

Rawi01 commented Oct 12, 2021

Managed to reproduce this (or at least something similar) in a single file:

package i2985;

import lombok.val;

public class Test {
	public void test() {
		val a = a(a(null));
	}

	public int a(String param) {
		return 0;
	}

	public int a(Integer param) {
		return 0;
	}
}

@Rawi01 Rawi01 self-assigned this Oct 12, 2021
@Maia-Everett
Copy link
Author

Ironically your case works for me (it correctly says "The method a(String) is ambiguous").

The original issue still occurs under latest Eclipse 2021-09.

@Rawi01
Copy link
Collaborator

Rawi01 commented Oct 16, 2021

Weird 😃
I'm working on a fix for the problem, should be done soon.

Rawi01 added a commit to Rawi01/lombok that referenced this issue Oct 22, 2021
@Rawi01
Copy link
Collaborator

Rawi01 commented Oct 22, 2021

I uploaded a pre-built version that should fix this, can you try it out @Maia-Everett?

@Maia-Everett
Copy link
Author

Seems fixed. I can't reproduce it with the class that always gave me this error before. Thank you!

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

Successfully merging a pull request may close this issue.

3 participants