How to disable "Access can be package-private" message in IntelliJ?

JavaIntellij Idea

Java Problem Overview


Developing an API, the warning message "Access can be package-package" in Java classes can be really annoying.

I've already spent some time going through the settings to find a way to disable this message but without any findings. Any idea how to disable the message?

Java Solutions


Solution 1 - Java

Go to Settings → Editor → Inspections then Java → Declaration redundancy → Declaration access can be weaker rule.
Here you can either disable it at all or select the suggestion options on the right pane:

enter image description here

Solution 2 - Java

To disable on a case by case basis, use

@SuppressWarnings("WeakerAccess")

Solution 3 - Java

The inspection rule is "Declaration access can be weaker" and there are two options which can be disabled "Suggest package-private visibility level..."

Solution 4 - Java

Move the cursor to public , press Alt + Enter and choose one of the options:
enter image description here

Solution 5 - Java

Another solution not mentioned so far: if you have a method that's declared public, and the IDE is telling you that there are no references to the method from outside the package, then perhaps you need to add a test case that calls that method from outside the package. In other words, treat the warning as signalling the absence of a test case for a public method.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionThomasView Question on Stackoverflow
Solution 1 - JavaDimaSanView Answer on Stackoverflow
Solution 2 - JavaseekingStillnessView Answer on Stackoverflow
Solution 3 - JavambossView Answer on Stackoverflow
Solution 4 - JavaJimHawkinsView Answer on Stackoverflow
Solution 5 - JavaMichael KayView Answer on Stackoverflow