Cannot find symbol when using the current module as an import
Remi Forax
forax at univ-mlv.fr
Tue Apr 8 06:24:36 UTC 2025
> From: "Josiah Noel" <josiahnoel at gmail.com>
> To: "compiler-dev" <compiler-dev at openjdk.org>
> Sent: Tuesday, April 8, 2025 4:12:16 AM
> Subject: Cannot find symbol when using the current module as an import
> Hey team,
> So I tried to modify some annotation processors to use the current module as an
> import to see if I could reduce the number of imports I have to generate.
> Unfortunately, it looks like when I use the current module as an import, it
> can't read the imports of its dependencies.
> Suppose I have:
>> module example {
>> requires com.fasterxml.jackson.databind;
>> }
> And I try:
>> import module example;
>> class Example {
>> void main() {
>> var mapper = new ObjectMapper(); //Cannot find symbol
>> }
>> }
> It fails to import the object mapper class.
Hello,
the require inside the module example should be a require transitive.
Now, please beware of import module, like an import *, those means that the list of types you are importing is unbounded and may change in the future (for example, if the module of jackson is updated), so your class Example may fail to compile in the future.
import module is nice for demos or for beginners, but if you have an import module in your code, updating a dependency becomes a source incompatible change, that why most company have a policy against import *, and i suppose this policy will be updated soon to include import module, which is a kind of import * on steroid.
> --
> Cheers, Josiah.
regards,
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20250408/8ae4c515/attachment-0001.htm>
More information about the compiler-dev
mailing list