19

I am getting this warning:

ScreenShot

When I click on the image, it just opens the associated Editor, but it doesn't say the line number where the warning is raised. I don't want to add @SuppressWarning("unchecked") on the whole class...

Any workaround/fix?

Luigi R. Viggiano
  • 8,103
  • 6
  • 46
  • 60
  • The warnings in the corresponding editor should navigate you to the problematic lines. – Denis Kniazhev Jan 09 '13 at 15:28
  • It doesn't. The editor is opened and the cursor is positioned on the first line. I think, it may be a limit on the javac compiler (so IntelliJ is unable to parse the message since the line number may be missing from the javac compiler). Eclipse uses its own compiler, which raises different warnings, but those warning are always including the line numbers. – Luigi R. Viggiano Jan 09 '13 at 15:30
  • 1
    Right, it will open on the first line, but on the right you should see the list of all warnings in corresponding editor (small yellow dots). There is also summary indicator (a green/yellow/red square in top right corner of the editor) which indicates overall 'health' of the editor. This should not be green for your case – Denis Kniazhev Jan 09 '13 at 15:35
  • like this: http://s9.postimage.org/4km1mlufz/image.png – Denis Kniazhev Jan 09 '13 at 15:37
  • 1
    @denisk it shows it green to me, and there is no sign on the bar – Luigi R. Viggiano Jan 09 '13 at 16:10
  • Does your project has language level at 5.0+ (Project Structure -> Project)? Do you have 'Unchecked Warning' inspection enabled and its severity level set to either Warning or Error (Settings -> Inspections -> General -> Unchecked Warning) ? – Denis Kniazhev Jan 09 '13 at 16:42
  • I have Language Level 6.0 and the inspection related to "Unchecked Warning" is selected. Using IntelliJ 12.0.1 – Luigi R. Viggiano Jan 09 '13 at 16:47
  • 1
    It is probably a bug in the "Unchecked Warning" inspection of IntelliJ IDEA. As far as I can tell, the inspection is supposed to catch this warning, but it does not. It is happening to me too. – Mike Nakis Jul 08 '13 at 23:04

4 Answers4

68

To compile with -Xlint:unchecked in IntelliJ IDEA:

  • Go to Settings dialog (Ctrl+Alt+S or +, )
  • Select Compiler > Java Compiler
  • Add following into the field Additional command line parameters:

    -Xlint:unchecked

  • Run your compile again

Community
  • 1
  • 1
devmake
  • 4,952
  • 1
  • 25
  • 26
  • 3
    Thank you so much for giving explicit instructions. I looked everywhere for detailed steps and your comment was the only one that explained HOW. Intellij has so many options; it's hard to find things. – Kelly Sep 22 '13 at 20:30
  • 1
    On OSX versions of IntelliJ, the Settings Dialog is at `Cmd`+`,` – Hans Z Mar 10 '14 at 15:10
  • I wish this was available in Android Studio. – IgorGanapolsky Jan 19 '16 at 15:14
  • 1
    In recent versions (I'm looking at IntelliJ 2018.1), the settings page is now "Build, Execution, Deployment > Compiler > Java Compiler". – Joe White Jul 20 '18 at 17:14
3

IntelliJ IDEA 15

A faster solution:

  • Press Ctrl + Shift + A
  • Type "Additional com" and press Enter:

    Additional command line parameters

  • Type -Xlint:unchecked > OK

    Xlint unchecked

  • Press Ctrl + Shift + F9 to recompile (or go to Build > Compile ... )

    • you can select a class / module from the project tree to specify what you want to be recompiled
  • You will see the line and the column where the problem appeared

    E.g.: Warning:(5,27) java: unchecked ...

Elrond_EGLDer
  • 47,430
  • 25
  • 189
  • 180
2

I'm not sure why your IDE does not show you generic warnings, but you can try to compile with

-Xlint:unchecked

to get more details.

Denis Kniazhev
  • 8,093
  • 5
  • 44
  • 60
  • thanks denisk, I'll try that. that's so obvious since it's what is suggested in the messages, but probably I would never thought that by myself. BTW, I think it will disable those warnings. I'll try it anyway and let you know. Thanks, and have a great day. – Luigi R. Viggiano Jan 09 '13 at 19:08
  • 2
    What does it mean to compile with `-Xlint:unchecked`. Are you talking about command line or IDE setting? – IgorGanapolsky Jan 19 '16 at 15:13
  • 2
    @IgorGanapolsky You can provide compile options in IDE's Run Configuration, as well as in command line. – Denis Kniazhev Jan 19 '16 at 15:51
0

I don't yet have the reputation to comment, but to add to @ROMANIA_engineer's answer - if you're on a Mac, the shortcut is Shift-Command-A.

The menu entry is Help/Find Action.

AlDante
  • 164
  • 1
  • 7