JavaFX 11 Module-Info.java Issue

Answered

Error:(1,1) java: module Reports reads package java.awt from both java.desktop and java.datatransfer

I'm clueless to this problem and how to fix it.

module-info.java is as follows:

module Reports {
requires javafx.graphics;
requires com.jfoenix;
requires javafx.fxml;
requires javafx.controls;
requires java.sql;
requires org.joda.time;
requires jna;
requires jna.platform;
requires java.datatransfer;
requires java.desktop;
}
0
15 comments

Hello,

Is it possible to share sample project for investigation? It works fine on my machine with IDEA 2018.3 EAP and JDK 9.

0

I have a metoo on this one. Is there a solution?

0

We need a sample project to understand why you have this problem.

0

FYI this issue happens because intellij automagically makes an entry, (maybe somewhere else in the project files),  which appears in build, execution deployment-->java compiler-->override compiler parameters per module section of settings. 

 

In the table there there will be an entry for  the effected module name and on the right half of the table in the "compilation optrions" column  there is an entry giving compiler parameters. On the effected module this appears:

add-exports java.datatransfer/java.awt=YOUR_MODULE_NAME

 

Since I  never wrote it, I know Intellij did. I don't know why. Since it was the only module with any entry under the column compilation options, it was suspicious. When I deleted it the problem went away. 

 

The error message during compilation only ever refers to the module-info.java file; it's misleading because there's nothing wrong with the module-info.java file. I confirmed  this by transfering the module into a new project and watching it compile without a problem. Also, more evidence there was nevver anything wrong with module-info.java , modules which use awt packages have module-info.java files identical to the effected module and they compile without an issue.  

 

HTH

1

IntelliJ IDEA never adds these options automatically, there is a quick fix that adds it, but it must be invoked manually by the user, see https://youtrack.jetbrains.com/issue/IDEA-224965 .

0

I see five checkboxes for javac on that cnofiguration page. Which one caused the entry in the table? AFAIK I have never checked or unchecked anything from this page. 

0

This intention action in the editor adds the options to the compiler:

It does not happen automatically.

0

FYI all it takes to trigger this compilation error is a completely empty project with 0 (zero or more) classes in  a module which requires java.desktop in its module-info.java and the presence of this compiler option. It's hard for me to imagine a modular project which would require this compiler option but yet has not  already required java.desktop. In any reasonable use case scenario I can think of, its addition is going to happen after java.destop has already been required  but I haven't seen as many use cases as JB has so I defer to your judgment. It seems like offering it as a suggestion might lead the developer to a loss of productivity as they try to run down the near infinite false possibilities which could possibly produce an error like this one.

 

 

0

Hello java developer,

Can you please describe in more details the issue that you experience. What compiler option do you have by default in empty project created that affects the compilation? Can you please share the sample of such a project (please create an issue at the YouTrack, https://youtrack.jetbrains.com/, attaching the sample or upload it to the https://uploads.services.jetbrains.com/ and share the project name here)? 

 

Thank you 

0

Olga,

 I described above what it takes to trigger the situation. I just checked back here because it happened again and I couldn't recall the solution .. lol... nothing I  am doing except what I  described above.  I am not taking any fast suggestion / auto-completion option except to require(s) javadesktop in the module-info.java file  when a class I wrote  uses awt in the module I wrote and desktop is not already required. That's all it takes. If you can't  repro using my previous post I am not sure I can offer any more insight.

 

HTH.

 

Thank you. 

0

Hello java developer,

In case I use i.e.

java.awt.Point

Package java.awt is declared in module java.desktop thus the suggestion to add it to module-info is quite reasonable. Please explain what behaviour do you expect?

When does the collision between the 

requires  java.datatransfer;
requires java.desktop;

occur for you?

Thanks

0

Olga,

 Hi. Thanks for looking at this. What I am understanding is you did what I described in my post above dated:

 
using java.awt.Point and did not have the problem I described.
 
I will do as I described using java.awt.Point as you did and then report back what happens back to you. 
 
 
0

java developer

 

Yes, I'm checking the described steps with v2020.2 Beta (https://www.jetbrains.com/idea/nextversion/).

0

Hi Olga,

I did it again and got the same result. If it's not happening on your machine then that's cool; I'll try to work it out from here.

Thanks !

0

java developer,

Sharing your sample project may really help to find out what the problem can be (https://youtrack.jetbrains.com/ or https://uploads.services.jetbrains.com/). Unfortunately for now it's not quite clear :(

0

Please sign in to leave a comment.