0

After a combination of Google / Stack Overflow searches I landed on this post which describes my exact problem: StackOverflowQuestion

The post defines this issue is an eclipse bug of version '2022-06': my version, as you can see in the 'Details' tab, comes exactly 1 year later, so I'm wondering if there's something I'm doing wrong, rather than there still being the same bug.

Details:

-MacOS Ventura on M2 Air -Using 'Eclipse IDE': 'About Eclipse':

Version: 2023-06 (4.28.0)

Build id: 20230608-1333

Steps to reproduce (default preferences used)

New Java Project > Finish (Project Name: 'TestProject')

[selected+right-clicked 'src' in 'Package Explorer' view]: New > Package (Name: 'test')

[selected+right-clicked package 'test']: New > Class (Name: 'CoolClass')

[initial modified 'CoolClass' code]:

package test;

import org.junit.Assert;

public class CoolClass {
    @Test
    public void testMethod() {
        int i = 1;
        Assert.assertTrue(i == 1);
    }
}

As expected, there were errors since I hadn't added the 'Junit 4 Library' to the build path. I then proceeded to do this by clicking the lightbulb icon which appeared next to the '@Test' snippet in the editor (as shown here: Image) and clicked on 'add JUnit 4 Library to the build path'.

Despite this, I continued to get these errors:Errors

As stated in the Stack Overflow post I linked above, upon deleting the 'module-info.java' file, these errors totally disappeared.

My questions are:

Is this still a bug or am I missing something? (Surely it can't be since it's been roughly a year right?)

Is having to delete the 'module-info.java' file to use JUnit a problem when coding in java? (I'm still learning to code in Java through the use of Eclipse, so don't have any experience on making a fully fledged 'Project' yet with modules and everything)

Why does removing the 'module-info.java' file tend to resolve certain issues? (I came across this phenomenon whilst reviewing possible duplicate questions proposed by Stack Overflow)

  • See ["The package java.sql is not accessible." in eclipse](https://stackoverflow.com/q/65273632). You need to `require` the modules you are using in your `module-info.java`. You cannot use any modules you don't `require`. See also https://dev.java/learn/modules/ for in-depth information about modules. – dan1st Jul 16 '23 at 19:12
  • No, this is not an Eclipse bug but how [`module-info.java`](https://en.wikipedia.org/wiki/Java_Platform_Module_System#Properties_of_modules) works. In the mentioned question there is not even a `module-info.java` file. I guess you referring to [this wrong answer](https://stackoverflow.com/a/72731049/6505250). As long as you don't know what `module-info.java` does, delete it, if needed you can recreate it later via right-click on the project _Configure > Create module-info.java_. I also recommend to use JUnit 5 rather than JUnit 4 when you start from scratch. Consider also to use Maven. – howlger Jul 17 '23 at 10:37

0 Answers0