Note that there are some explanatory texts on larger screens.

plurals
  1. POunsafe operation, unchecked conversion
    primarykey
    data
    text
    <p>When I compile the following class (available <a href="https://github.com/lviggiano/owner/blob/master/src/test/java/org/aeonbits/owner/multithread/ThreadBase.java" rel="nofollow">here</a>, the main method has been added to reproduce the problem in a single class), I get the following compiler warning in IntelliJ or from maven command line:</p> <pre><code>java: /Users/luigi/var/src/owner/src/test/java/org/aeonbits/owner/multithread/ThreadBase.java uses unchecked or unsafe operations. java: Recompile with -Xlint:unchecked for details. </code></pre> <p>Then I added the -Xlint:unchecked to maven to see the details and I got this:</p> <pre><code>[WARNING] /Users/luigi/var/src/owner/src/test/java/org/aeonbits/owner/multithread/ThreadBase.java:[74,45] unchecked conversion required: java.util.List&lt;java.lang.Throwable&gt; found: java.util.List </code></pre> <p>The class source follows (the main has been added to reproduce the problem in a single class):</p> <pre><code>package org.aeonbits.owner.multithread; import org.aeonbits.owner.Config; import org.aeonbits.owner.UtilTest.MyCloneable; import java.util.ArrayList; import java.util.List; import static org.aeonbits.owner.UtilTest.debug; abstract class ThreadBase&lt;T extends Config&gt; extends Thread implements MyCloneable { private static long counter = 0; final long uniqueThreadId = ++counter; final T cfg; final Object lock; final int loops; final List&lt;Throwable&gt; errors = new ArrayList&lt;Throwable&gt;(); ThreadBase(T cfg, Object lock, int loops) { this.cfg = cfg; this.lock = lock; this.loops = loops; } @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } @Override public void run() { synchronized (lock) { try { lock.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } } for (int i = 0; i &lt; loops; i++) { debug("%s[%d] started loop #%d.\n", getClass().getName(), uniqueThreadId, i); try { execute(); } catch (Throwable throwable) { debug("%s[%d] thrown an error in loop #%d.\n", getClass().getName(), uniqueThreadId, i); errors.add(throwable); } yield(); debug("%s[%d] completed loop #%d.\n", getClass().getName(), uniqueThreadId, i); } } abstract void execute() throws Throwable; public List&lt;Throwable&gt; getErrors() { return errors; } public static void main(String[] args) { ThreadBase t = new ThreadBase(null, new Object(), 10) { @Override void execute() throws Throwable { } }; List&lt;Throwable&gt; errors = t.getErrors(); // ^ compiler reports the warning here! } } </code></pre> <p>Additional details:</p> <pre><code>$ mvn --version Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100) Maven home: /Users/luigi/opt/apache-maven-3.0.4 Java version: 1.7.0_25, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.8.4", arch: "x86_64", family: "mac" </code></pre> <p>In pom.xml I added compiler.source and compiler.target 1.5 since my library is targetted to jdk 1.5 or better:</p> <pre><code>&lt;build&gt; &lt;pluginManagement&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt; &lt;version&gt;3.1&lt;/version&gt; &lt;configuration&gt; &lt;source&gt;1.5&lt;/source&gt; &lt;target&gt;1.5&lt;/target&gt; &lt;compilerArgument&gt;-Xlint:unchecked&lt;/compilerArgument&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/pluginManagement&gt; </code></pre> <p>Can anybody explain me what is wrong here?</p> <p>For me, it does not make any sense as t.getErrors() returns a List:</p> <pre><code>List&lt;Throwable&gt; errors = t.getErrors(); </code></pre> <p>What's wrong here?!?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload