eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
164 stars 130 forks source link

Possibly bogus warning for public exported types when the export target contains those types #3067

Open nlisker opened 4 weeks ago

nlisker commented 4 weeks ago

Suppose a module dep that exports package dep with class dep.D. And suppose another module:

module App {
    requires dep;

    exports app to dep;
}

then

package app;

public class A {
    public dep.D d;
}

emits a warning:

The type D from module dep may not be accessible to clients due to missing 'requires transitive'

While it's true that it may not be accessible, since the module exposes the package (and class) to the module that defines that class, we can know that it will be accessible.

Can the compiler be smarter and check if the targets of an export have access to the exposed types?

jukzi commented 4 weeks ago

I guess as long as you don't contribute such improvement nothing will happen.

stephan-herrmann commented 4 weeks ago

I believe one thing is missing from the problem description:

see:

Suppose a module dep that exports package dep with class dep.D.

and:

exports app to dep;

In order for that export to take effect module dep would also need to require module App, right?

Thus we have a cyclic dependency, which brings us back to https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2122#issuecomment-1985548047

LMK if I missed something.

nlisker commented 4 weeks ago

In order for that export to take effect module dep would also need to require module App, right?

I don't think so because it can be accessed reflectively. See https://stackoverflow.com/questions/53035454/javafx-module-javafx-graphics.