IJ adds unnecessary "requires" statements to module-info.java

Answered

I couldn't figure out when exactly that happens, but IJ automatically adds “requires” statements which are definitely not necessary. I suspect that this is related to transitive module requirements, but I'm not sure. Our project is quite large with a lot of modules and before each commit, you have to check the module-info files for such automatically added statements and revert them.

Is there a way to turn that feature off?

0
5 comments

Hi Harald,

It is regulated by customizable inspections in File | Settings | Editor | Inspections | Java that are probably triggered automatically on save or during commit checks.

Could you provide some code samples to understand which statements are added exactly? 

A small test project would be great too. You can upload it securely to our server (make sure to share the id of the upload here so that I can find it).

0

All save actions and commit checks are turned off. It happens during editing, occasionally. It would be really nice if such automatic changes were configurable in the same way as auto imports already are. Should I file a feature bug?

0

Now I know how it happens: when editing a file, chances are high that due to the IJ autocompletion sometimes unwanted code is inserted. If that code requires changes in the module-info file it will be modified accordingly. However, when the wrong code is then removed the imports are automatically fixed but the changes in the module-info file are not reverted.

This is dangerous behavior. Unwanted imports don't affect the bytecode. Unwanted “require” statements, however, do! Modifying a module-info file should be a mindful step since it changes the module dependency hierarchy (JPMS). 

0

due to the IJ autocompletion sometimes unwanted code is inserted

Regular code completion suggestions will only be inserted if you accept them with Enter, Space, or TAB by default.

You can tweak code completion settings under File | Settings | Editor | General | Code Completion - for example, to only show the completion popup on demand (e.g. by pressing Ctrl+Space).

 

There is also a probability that you are referring to the ‘Inline Completion’ functionality, which is a part of AI-assisted completion. Its settings and behavior can be controlled in File | Settings | Editor | General | Inline Completion

You can disable it altogether to see if it helps your editing be more predictable and reduce the number of accidentally accepted suggestions.

0

Indeed I'm referring to the AI-assisted completion, which is useful in most cases. Turning it off is definitely not a solution ;)

I will file a feature request…

0

Please sign in to leave a comment.