eclipse-jdt / eclipse-jdt/eclipse.jdt.ui

Running Junit5 tests with module-info fails

Open
#1,812 8 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
59
Forks
127
Avg merge
23h 30m
Merged PRs (30d)
35

Description

## Given
- Maven project A has production code and contains a module-info (module A)
- Maven project B has test code (Junit 5) for project A and contains a module-info ( module B requires module A)
- After importing project A and B in Eclipse, project B has a project reference to project A
- The standalone Maven build executes the unit tests without failures given this maven-surefire-plugin configuration:
```xml

org.apache.maven.plugins
maven-surefire-plugin
3.5.2

true
false
false
1
false
-javaagent:${org.mockito:mockito-core:jar}

```

## Expectation
I expected Eclipse to run the junit tests successfully since the Maven build executes correctly, proving that dependencies and and module references are setup correctly.

## Findings
- When running the unit tests in project B in Eclipse a popup titled Problem Occurred with description: `An internal error occurred during: "Launching java (6)".
Index 0 out of bounds for length 0`
- The stacktrace in de Eclipse's log is:
```
!MESSAGE An internal error occurred during: "Launching java (6)".
!STACK 0
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate.enumerateTypesInPackage(JUnitLaunchConfigurationDelegate.java:543)
at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate.collectExecutionArguments(JUnitLaunchConfigurationDelegate.java:473)
at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate.getVMRunnerConfiguration(JUnitLaunchConfigurationDelegate.java:182)
at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate.launch(JUnitLaunchConfigurationDelegate.java:275)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:805)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:716)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1054)
at org.eclipse.debug.internal.ui.DebugUIPlugin$1.run(DebugUIPlugin.java:1257)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
```
- If I remove the module-info.java file from test project B, Eclipse starts executing unit tests. However, this is an undesirable workaround since it causes test failures when the code under test uses the [ServiceLoader](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/ServiceLoader.html) mechanism and needs to find `provides interface with implementation` clauses in the module descriptor of the test project.

## Tested under this environment:
* OS & version
Linux 6.8.0-49-generic 49-Ubuntu SMP PREEMPT_DYNAMIC Mon Nov 4 02:06:24 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
* Eclipse IDE/Platform version:
Version: 2024-09 (4.33.0)
Build id: 20240905-0614
No additional plugins installed
* JDK:
java version "21.0.4" 2024-07-16 LTS
Java(TM) SE Runtime Environment (build 21.0.4+8-LTS-274)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.4+8-LTS-274, mixed mode, sharing)
* Maven:
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)

Contributor guide

Open the contributing guide

Research direction

Start in JUnitLaunchConfigurationDelegate, especially enumerateTypesInPackage at line 543 and collectExecutionArguments, using the reported Eclipse launch stack trace as the entry point. Reproduce the Maven project A/B setup with module-info.java files in Eclipse 2024-09 and compare it with the working case without the test module descriptor. Done means JUnit 5 tests launch without the array-bounds error while retaining module-based ServiceLoader behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.