17

It really annoys me that IntelliJ highlights certain 'errors' (that don't prevent successful compilation) the same way that real errors are highlighted. For example, a magic number is not really an error, but it will be flagged in exactly the same way as an incompatible type error.

How can I change this?

4 Answers4

17

Go to Settings -> Inspections. Then you need to search through the long list for the offending inspection, which you can get the name of by hovering on the warning marker in the margin. You can change the severity of the inspection, whether it's an error, warning, etc. or just disable it altogether.

Edit: if you search for "magic" in Settings, you get the following, which should be helpful:

enter image description here

Jasperan
  • 2,154
  • 1
  • 16
  • 40
hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
  • 3
    It should be noted that many warnings represent logic errors or maintainability issues. It's often better to look carefully at your code and determine whether each warning is valid (using the @SuppressWarnings annotation if needed) than to disable the warning entirely. It varies on a case by case basis, but I would argue that most warnings have something valuable to say. – Michael Calvin Feb 25 '14 at 15:51
17

Whenever you see an inspection warning/error you can place the caret on it and press Alt+Enter (a light bulb also appears that tells you that). A menu will appear with suggested quick fixes. You may need to open a submenu by pressing Right, and you'll find "Edit inspection settings" there. Having invoked that, you may proceed as in hvgotcodes's answer :), it's just a faster way of getting to those settings.

Peter Gromov
  • 17,615
  • 7
  • 49
  • 35
9

As Michael Calvin said, you can use the SuppressWarnings annotation. For example:

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")

See https://github.com/JetBrains/intellij-community/blob/master/plugins/InspectionGadgets/src/inspectionDescriptions/OptionalUsedAsFieldOrParameterType.html

Usually searching the internet for the exact description leads me to this.

Pang
  • 9,564
  • 146
  • 81
  • 122
Karl the Pagan
  • 1,944
  • 17
  • 17
  • this would be a terrible idea - you'll end up sharing your settings with everyone else via version control, no? – bharal May 13 '19 at 21:51
  • 1
    @bharal In some cases that would be desirable. But it is up to the developer to decide on a per case basis if you want to go for [@Peter Gromov's solution](https://stackoverflow.com/a/11703621/426371) or this one. Don't overuse this solution. Michael Calvin made this clear in his [original comment](https://stackoverflow.com/questions/11703601#comment33377512_11703621). – neXus Jun 20 '19 at 11:24
1

Not directly relevant to the OP, but may be of use to future Googlers

I got to this question while trying to figure out how to disable IntelliJ IDEA's warnings about Guava functionalities that have been replaced by Java 8 features. I'm not able to use the Java 8 versions of these features in my case because of a library we're using that was built with Guava (despite being a Java 8 project). So to solve that, I added a SuppressWarnings annotation before any class using Guava:

@SuppressWarnings(Guava)
public final class...
Pang
  • 9,564
  • 146
  • 81
  • 122
Jonathan E. Landrum
  • 2,748
  • 4
  • 30
  • 46