kohlschutter / junixsocket

Unix Domain Sockets in Java 7 and newer (AF_UNIX), AF_TIPC, AF_VSOCK, and more
Apache License 2.0
438 stars 114 forks source link

Lack of com.kohlschutter:compiler-annotations dependency leads to compiler warnings #129

Closed norrisjeremy closed 1 year ago

norrisjeremy commented 1 year ago

Describe the bug The com.kohlschutter:compiler-annotations needs to be declared as a full dependency, not just a provided scope dependency, else it leads to compiler warnings when -Xlint:all is enabled, like this in downstream projects that use junixsocket:

[WARNING] COMPILATION WARNING : 
[INFO] -------------------------------------------------------------
[WARNING] Cannot find annotation method 'value()' in type 'com.kohlschutter.annotations.compiletime.SuppressFBWarnings': class file for com.kohlschutter.annotations.compiletime.SuppressFBWarnings not found
[WARNING] Cannot find annotation method 'value()' in type 'com.kohlschutter.annotations.compiletime.SuppressFBWarnings'
[WARNING] Cannot find annotation method 'value()' in type 'com.kohlschutter.annotations.compiletime.SuppressFBWarnings'
[WARNING] Cannot find annotation method 'value()' in type 'com.kohlschutter.annotations.compiletime.SuppressFBWarnings'
[INFO] 4 warnings 
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /.../jsch/src/main/java/com/jcraft/jsch/JUnixSocketFactory.java: warnings found and -Werror specified
[INFO] 1 error

Guava faced a similar issue several years ago, see https://github.com/google/guava/issues/2721.

This happens because maven does not pull in a transient dependency for com.kohlschutter:compiler-annotations (since it is marked with as a provided scope dependency of com.kohlschutter.junixsocket:junixsocket-common).

This has forced us to explicitly declare a direct dependency on com.kohlschutter:compiler-annotations over at https://github.com/mwiede/jsch, since we enable -Xlint:all -Werror in our javac flags.

We would rather not have to declare an explicit dependency on com.kohlschutter:compiler-annotations since we aren't actually directly utilizing any of these annotations in the JSch code.

To Reproduce

$ cat Foo.java
public class Foo {
  public void foo() throws Exception {
    var foo = org.newsclub.net.unix.AFUNIXSocketChannel.open();
  }
}
$ javac -Xlint:all -Werror -cp junixsocket-common-2.6.2.jar Foo.java
junixsocket-common-2.6.2.jar(/org/newsclub/net/unix/AFSocketChannel.class): warning: Cannot find annotation method 'value()' in type 'SuppressFBWarnings': class file for com.kohlschutter.annotations.compiletime.SuppressFBWarnings not found
junixsocket-common-2.6.2.jar(/org/newsclub/net/unix/AFSocketChannel.class): warning: Cannot find annotation method 'value()' in type 'SuppressFBWarnings'
error: warnings found and -Werror specified
1 error
2 warnings

Expected behavior Project to compile successfully.

Output/Screenshots

[WARNING] COMPILATION WARNING : 
[INFO] -------------------------------------------------------------
[WARNING] Cannot find annotation method 'value()' in type 'com.kohlschutter.annotations.compiletime.SuppressFBWarnings': class file for com.kohlschutter.annotations.compiletime.SuppressFBWarnings not found
[WARNING] Cannot find annotation method 'value()' in type 'com.kohlschutter.annotations.compiletime.SuppressFBWarnings'
[WARNING] Cannot find annotation method 'value()' in type 'com.kohlschutter.annotations.compiletime.SuppressFBWarnings'
[WARNING] Cannot find annotation method 'value()' in type 'com.kohlschutter.annotations.compiletime.SuppressFBWarnings'
[INFO] 4 warnings 
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /.../jsch/src/main/java/com/jcraft/jsch/JUnixSocketFactory.java: warnings found and -Werror specified
[INFO] 1 error

Environment (please complete the following information):

Notes https://github.com/mwiede/jsch/blob/master/pom.xml#L96 https://github.com/mwiede/jsch/blob/master/pom.xml#L101 https://github.com/google/guava/issues/2721

Lastly, please make sure to test the problem still occurs on the latest version of junixsocket Yes, this occurs with current 2.6.2 release.

norrisjeremy commented 1 year ago

FYI, it appears that using disabling classfile type warnings (-Xlint:all,-classfile) seems to workaround this issue.

kohlschuetter commented 1 year ago

Thanks for bringing this up, @norrisjeremy !

I'm reluctant to add compiler-annotations as a full dependency, mostly because these annotations are supposed to be specific to compiling the class files/building the project. The fact that they get exported to users of the junixsocket library is actually undesired, but deemed acceptable.

How much of a problem is this to you, now that you have a workaround? I'm asking because a proper fix is actually far from being straightforward (with including compiler-annotations as a dependency not being an option at all).

norrisjeremy commented 1 year ago

Hi @kohlschuetter,

I think disabling the classfile warnings will suffice for us, thanks!

Thanks, Jeremy