<div dir="ltr"><div>Source structure:</div><div><br></div>src<br>    |   module-info.java<br>    \---my<br>        \---nice<br>            \---project<br>                |   Main.java<br>                \---pkg<br>                    +---a<br>                    |       SomeInterface.java<br>                    \---b<br>                            SomeRecord.java<br><div><br></div><div>I've tried both commands with and without the module import and they both fail:</div><div><br></div><div>java --enable-preview src/my/nice/project/Main.java<br></div><div><br></div><div><br></div><div>javac --release 23 --enable-preview -d ./mod ./src/module-info.java ./src/my/nice/project/Main.java ./src/my/nice/project/pkg/a/SomeInterface.java ./src/my/nice/project/pkg/b/SomeRecord.java<br></div><div><br></div><div>However, exporting a package to the my.nice.project module 

and including the module import both commands work. </div><div><br></div><div><br></div><div>.\src\my\nice\project\pkg\a\SomeInterface.java:7: error: cannot find symbol<br>    public SomeRecord someMethod();<br>           ^<br>  symbol:   class SomeRecord<br>  location: interface SomeInterface<br>.\src\my\nice\project\Main.java:7: error: cannot find symbol<br>        SomeInterface someInterface = new SomeInterface() {<br>        ^<br>  symbol:   class SomeInterface<br>  location: class Main<br>.\src\my\nice\project\Main.java:7: error: cannot find symbol<br>        SomeInterface someInterface = new SomeInterface() {<br>                                          ^<br>  symbol:   class SomeInterface<br>  location: class Main<br>.\src\my\nice\project\Main.java:9: error: cannot find symbol<br>            public SomeRecord someMethod() {<br>                   ^<br>  symbol: class SomeRecord<br>.\src\my\nice\project\Main.java:8: error: method does not override or implement a method from a supertype<br>            @Override<br>            ^<br>.\src\my\nice\project\Main.java:10: error: cannot find symbol<br>                return new SomeRecord();<br>                           ^<br>  symbol: class SomeRecord<br>6 errors<br></div><div><br></div><div><br></div><div>Best regards,</div><div><br></div><div>Thiago</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em sex., 13 de set. de 2024 às 15:53, Alex Buckley <<a href="mailto:alex.buckley@oracle.com">alex.buckley@oracle.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">If removing the imports doesn't fix the errors, then I'm suspicious of <br>
your compiler setup.<br>
<br>
Please describe on this mailing list the commands you're using and the <br>
actual javac errors that you see.<br>
<br>
Alex<br>
<br>
On 9/13/2024 9:41 AM, Thiago Henrique Hupner wrote:<br>
> Removing the imports still doesn't fix the errors.<br>
> <br>
> I've create a Github repo with the reproducer: <a href="https://github.com/" rel="noreferrer" target="_blank">https://github.com/</a> <br>
> Thihup/module-import-bug<br>
> <br>
> Best regards,<br>
> <br>
> Thiago<br>
> <br>
> <br>
> Em sex., 13 de set. de 2024 às 12:41, Alex Buckley <br>
> <<a href="mailto:alex.buckley@oracle.com" target="_blank">alex.buckley@oracle.com</a> <mailto:<a href="mailto:alex.buckley@oracle.com" target="_blank">alex.buckley@oracle.com</a>>> escreveu:<br>
> <br>
>     I assume that the package my.nice.project is colocated with the other<br>
>     two packages -- my.nice.project.pkg.{a,b} -- in the module<br>
>     my.nice.project.<br>
> <br>
>     If so, then all three packages should be able to access each others'<br>
>     public types (SomeInterface, SomeRecord) without error.<br>
> <br>
>     The fact that you're getting an error looks like a javac bug.<br>
> <br>
>     You don't need to `import module my.nice.project` in the source<br>
>     files of<br>
>     that module. Try removing those imports and see if my.nice.project.Main<br>
>     compiles (it should).<br>
> <br>
>     Alex<br>
> <br>
>     On 9/13/2024 5:00 AM, Thiago Henrique Hupner wrote:<br>
>      > Dear Amber Team,<br>
>      ><br>
>      > I hope you're doing well. I’ve encountered a behavior related to JEP<br>
>      > 476: Module Import Declarations and wanted to ask for clarification.<br>
>      ><br>
>      > I’m working with a module setup where two packages are defined<br>
>     but not<br>
>      > initially exported:<br>
>      ><br>
>      > |module my.nice.project { //exports my.nice.project.pkg.a to<br>
>      > my.nice.project; //exports my.nice.project.pkg.b to<br>
>     my.nice.project; } |<br>
>      ><br>
>      > Here’s a simplified version of the code structure:<br>
>      ><br>
>      ><br>
>      > |package my.nice.project;<br>
>      > |<br>
>      > |<br>
>      > |import module my.nice.project;|<br>
>      ><br>
>      > |<br>
>      > |public class Main { public static void main(String[] args)<br>
>      > { SomeInterface someInterface = new SomeInterface() { @Override<br>
>     public<br>
>      > SomeRecord someMethod() { return new SomeRecord(); } }; } }|<br>
>      ><br>
>      > |<br>
>      > |<br>
>      > |package my.nice.project.pkg.a; import module my.nice.project;|<br>
>      > |<br>
>      > |<br>
>      > |public interface SomeInterface { public SomeRecord someMethod(); }|<br>
>      ><br>
>      > |package my.nice.project.pkg.b; public record SomeRecord() {} |<br>
>      ><br>
>      > When attempting to compile this code with the exports commented<br>
>     out, I<br>
>      > received several "cannot find symbol" errors. However, after<br>
>      > uncommenting the exports:<br>
>      ><br>
>      ><br>
>      > |exports my.nice.project.pkg.a to my.nice.project; exports<br>
>      > my.nice.project.pkg.b to my.nice.project; |<br>
>      ><br>
>      > The code compiled and ran as expected.<br>
>      ><br>
>      > Given this behavior, I wanted to confirm if this restriction on<br>
>     package<br>
>      > visibility within a module is the intended design under the Amber<br>
>      > project and the module system, or if there’s another approach or<br>
>     best<br>
>      > practice I might be overlooking in terms of package exports.<br>
>      ><br>
>      > Thank you for your time and insight.<br>
>      ><br>
>      > Best regards,<br>
>      ><br>
>      > Thiago<br>
>      ><br>
> <br>
<br>
</blockquote></div>