Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

suppress unchecked warnings in ant

843793Jan 29 2009 — edited Feb 3 2009
Hi there,

I wish to suppress warnings such as these in my ant build;
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
Going on what the javac ant task allows and what javac itself says to do I think I should have something like;
 <javac srcdir="${srcDir}" destdir="${classDir}">
     <!-- This is only allowed for the srcDir.  Do not do this anywhere else -->
     <compilerarg line="-Xlint:"-unchecked""/>
 </javac>
But this doesn't appear to do what I want. Anyone know exactly how to get these warnings suppressed?

Comments

Alan.M
the attribute for the task javac

<javac nowarn="on">

.....

</javac>

Regards,
Alan Mehio
London,UK
843793
Thanks Alan. Will this suppress all warnings? I only wish to suppress the unchecked ones.
843793
Hers's an example (just compile on command line);
import java.util.ArrayList;

public class CompilerTest
{
public static void main(String args[])
{
ArrayList list = new ArrayList();
list.add("John");
System.out.println("Element in list: "+list.get(0));
}
}
Compiling with;

1. Ordinary compilation
javac CompilerTest.java
Note: CompilerTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2. -Xlint:unchecked
javac -Xlint:unchecked CompilerTest.java
CompilerTest.java:22: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.ArrayList
list.add("John");
^
1 warning
I want something which does the opposite of this (i.e. doesn't warn me at all about unchecked warnings.

3. -Xlint:-unchecked (this is what the compiler help tells me to do, see the non-standard options section on
http://java.sun.com/javase/6/docs/technotes/tools/windows/javac.html#options)
javac -Xlint:-unchecked CompilerTest.java
Note: CompilerTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
mcnepp
The compiler message is not really a warning - it merely tells you that there would be warnings if you enabled them ;-)
Hence, I don't think there is a command line switch to turn this message off.

I'm amfraid the only way of quietening the compiler is to use the @SuppressWarnings("unchecked") annotation throughout your code.
843793
Thanks McNepp,

however this comment in the javac synopsis doesn't make sense if that's the case;

-Xlint:-name
Disable warning name, where name is one of the warning names supported for -Xlint:name, below.
-Xlint:unchecked
Give more detail for unchecked conversion warnings that are mandated by the Java Language Specification.

So by that logic I thought doing -Xlint:-unchecked would disable all warnings about unchecked (including the note that's displayed).
796085
Really, you're better off doing it in the source code with annotations anyway. At least that way you'll be able to suppress them on a case-by-case basis, and you'll get warnings from the compiler for any new ones that have been introduced so you can go fix/annotate them. Plus should you ever change compilers you're not using compiler-specific switches, etc.
EJP
-Xlint:-name
Disable warning name, where name is one of the warning names supported for -Xlint:name, below.
That's obviously incorrect. It should read 'enable'.
mcnepp
ejp wrote:
-Xlint:-name
Disable warning name, where name is one of the warning names supported for -Xlint:name, below.
That's obviously incorrect. It should read 'enable'.
No, it was correct. -Xlint:-name disables the warning name whereas -Xlint:name enables it!

(Watch the hyphen before name )
843793
-Xlint:-name disables the warning name

That seems to have no effect (see my earlier post).
EJP
-Xlint:-unchecked is the default. If you turn it off you get a warning per unchecked line of code. If you turn it on, or leave it on, you get one warning concerning the lot of them. Those are your choices.

Is one warning really such a problem?
mcnepp
ejp wrote:
-Xlint:-unchecked is the default. If you turn it off you get a warning per unchecked line of code. If you turn it on, or leave it on, you get one warning concerning the lot of them. Those are your choices.
If you substitute every "off" with "on" and vice versa, the above sentence pretty much sums it up.
843793
Thanks all for your help.

McNeep's suggestion that I am seeing Note's rather than warnings plus ejp's that -Xlint:-unchecked is the default were most helpful but thanks to all.

Regards,

John

Edited by: johnmmcparland on 03-Feb-2009 08:15
EJP
-Xlint:-unchecked is the default. If you turn it off you get a warning per unchecked line of code. If you turn it on, or leave it on, you get one warning concerning the lot of them. Those are your choices.
If you substitute every "off" with "on" and vice versa, the above sentence pretty much sums it up.
No. Read it again. -Xlint-unchecked turns multiple unchecked warnings off. -Xlint:checked turns them on. If you turn off the offness of multiple unchecked warnings you are turning the warnings on. OK? If you turn on the offness you are turning the warnings off.

I think my original statement is clearer frankly.
1 - 13
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 3 2009
Added on Jan 29 2009
13 comments
4,111 views