You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by wjm wjm <zz...@gmail.com> on 2018/10/26 01:51:51 UTC

how to suppress warning of "try.resource.not.referenced"

if delete the red line, then even @SuppressWarnings("all")  can not
suppress this warning
must reference the variable?

public static boolean canTcpListen(InetAddress address, int port) {
    try (ServerSocket ss = new ServerSocket(port, 0, address)) {
      ss.getLocalPort();
      return true;
    } catch (IOException e) {
      return false;
    }
  }

Re: how to suppress warning of "try.resource.not.referenced"

Posted by wjm wjm <zz...@gmail.com>.
got it.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.1</version>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <showDeprecation>true</showDeprecation>
    <showWarnings>true</showWarnings>
    <compilerArgs>
      <arg>-Werror</arg>
      <arg>-Xlint:all</arg>
      <!--care for jdk8/jdk7 compatible problem-->
      <arg>-Xlint:-classfile</arg>
      <!--not referenced in try-with-resources-->
      <arg>-Xlint:-try</arg>
    </compilerArgs>
  </configuration>
</plugin>



wjm wjm <zz...@gmail.com> 于2018年10月26日周五 上午9:51写道:

> if delete the red line, then even @SuppressWarnings("all")  can not
> suppress this warning
> must reference the variable?
>
> public static boolean canTcpListen(InetAddress address, int port) {
>     try (ServerSocket ss = new ServerSocket(port, 0, address)) {
>       ss.getLocalPort();
>       return true;
>     } catch (IOException e) {
>       return false;
>     }
>   }
>