-Xlint:unchecked

-Xlint:unchecked

by Christian Gasde -
Number of replies: 3

Hi,

in Coderunner I began a new "java_class" -project.

It's simple code that deals with generics.

While trying to run the code I get the following error:

"Note: __tester__.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details."

Where is the place to tell coderunner: -Xlint:unchecked ?

Thankx for help!

Best Regards
Chris

In reply to Christian Gasde

Re: -Xlint:unchecked

by Richard Lobb -
Compile parameters for a question or prototype are set via Customise > Advanced customisation > Sandbox > Parameters. Something like

{"compileargs": ["-Xrs", "-Xss8m", "-Xmx200m", "-Xlint:unchecked"]}

should work. But this will just result in more information about the unsafe operation - it won't turn the message off. AFAIK there's no way to disable the message completely, though I haven't used Java in years so you should check that.

If you want to filter the message from the output you have a much harder job. See this discussion.
In reply to Richard Lobb

Re: -Xlint:unchecked

by Christian Gasde -
Thank you very much! I'm not the admin, but I sent your information to our adminboard.

We found one other workaround:

@SuppressWarnings("unchecked") <------------- with this annotation our code is running in coderunner
public static void main(String[] args) {

/* getypte Orte mit Integer */
Integer[] iArr = {63, 98, 72, 4, 6, 63, 57, 55, 83, 29 };

Ort[] ortInts;
ortInts = new Ort[iArr.length]; <----PROBLEM: Type safety: The expression of type Ort[] needs unchecked conversion to conform to Ort[]
...

In Eclpise we only get a warning, but the execution doesn't stop. ....

Best Regards
Chris
In reply to Christian Gasde

Re: -Xlint:unchecked

by Anton Dil -
I believe that the message is really a bit out of date, as it can be generated by my more than one kind of issue. From Java 7 there was a new category for Xlint, rawtypes, and raw type issues generate exactly the same warning. However, -Xlint:unchecked since Java 7 only reports on unchecked type conversions. If your issue is actually that you used a raw type, recompiling with Xlint:unchecked will not tell you where you did that.

An example is where you use a raw return type from a method. In this case you require -Xlint:rawtypes, or I would use Xlint:rawtypes,unchecked, since we don't know what kind of code actually caused that message.

I would not suppress the message as I want students to recognise the code smell. It is however a warning, rather than an error, and it is somewhat confusing that Coderunner presents it like a compilation error.

ChatGPT says this compiler message is "wrong -- but stable wrong".

Possibly (I've not tried it) you could also pass -Xlint:none if you want to suppress all the linter warnings.