Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error due to ExecutorService API change in JDK 19 #285

Closed
cushon opened this issue Dec 9, 2022 · 5 comments · Fixed by #287
Closed

Compilation error due to ExecutorService API change in JDK 19 #285

cushon opened this issue Dec 9, 2022 · 5 comments · Fixed by #287
Assignees
Milestone

Comments

@cushon
Copy link
Contributor

cushon commented Dec 9, 2022

Version

3b16da4

Bug description

Starting in JDK 19, ExecutorService implements AutoCloseable: openjdk/jdk@00e6c63#diff-139913957207a1eeaa338c35b269f2c566b358590ae62dd2a8063e98bb5b0456

This change causes a compilation error in mina-sshd.

Actual behavior

cd ~/sshd-common
mvn clean package -Djava.sdk.version=19
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sshd-common: Compilation failure: Compilation failure:
[ERROR] /usr/local/google/home/cushon/src/mina-sshd/sshd-common/src/main/java/org/apache/sshd/common/util/threads/NoCloseExecutor.java:[43,8] org.apache.sshd.common.util.threads.NoCloseExecutor is not abstract and does not override abstract method close() in java.nio.channels.Channel
[ERROR] /usr/local/google/home/cushon/src/mina-sshd/sshd-common/src/main/java/org/apache/sshd/common/util/threads/CloseableExecutorService.java:[29,8] types java.util.concurrent.ExecutorService and org.apache.sshd.common.Closeable are incompatible;
[ERROR]   interface org.apache.sshd.common.util.threads.CloseableExecutorService inherits unrelated defaults for close() from types java.util.concurrent.ExecutorService and org.apache.sshd.common.Closeable
[ERROR] /usr/local/google/home/cushon/src/mina-sshd/sshd-common/src/main/java/org/apache/sshd/common/util/threads/SshThreadPoolExecutor.java:[35,8] types org.apache.sshd.common.Closeable and java.util.concurrent.ExecutorService are incompatible;
[ERROR]   class org.apache.sshd.common.util.threads.SshThreadPoolExecutor inherits unrelated defaults for close() from types org.apache.sshd.common.Closeable and java.util.concurrent.ExecutorService
[ERROR] -> [Help 1]

Expected behavior

I expected the project to compile

Relevant log output

Apache Maven 3.8.6
Maven home: /usr/share/maven
Java version: 19.0.1, vendor: Oracle Corporation
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", arch: "amd64", family: "unix"

Other information

No response

@tomaswolf
Copy link
Member

Ooof. An API break in the JDK that's not even mentioned in the change notes. (At least I didn't see it there.)

That's going to be "fun" to sort out. It's the kind of fun I could do without.

The immediate issue seems to be that org.apache.sshd.common.Closeable has a default method for close(), and now the ExecutorService also does. Additionally org.apache.sshd.common.Closeable wrongly extends java.nio.channels.Channel. Just having an isOpen() and a close() method doesn't make it a channel.

@cushon
Copy link
Contributor Author

cushon commented Dec 10, 2022

The CSR for the change (https://bugs.openjdk.org/browse/JDK-8285450) does at least acknowledge this could happen:

The introduced methods are in public classes and interfaces for which it is conceivable but highly unlikely that users have clashing existing methods in implementation classes or subclasses

Based on some testing I've been doing with 19 this problem does seem to be very rare.

tomaswolf added a commit to tomaswolf/mina-sshd that referenced this issue Dec 10, 2022
ExecutorService implements AutoCloseable in Java 19 and provides a
default method for close(). This conflicts in CloseableExecutorService,
which mixes in org.apache.sshd.common.Closeable, which has its own
default method for close().

As a minimum fix add overrides of close() as needed, explicitly calling
the Apache MINA sshd variant of close().

Bug: apache#285
@tomaswolf tomaswolf self-assigned this Dec 10, 2022
@tomaswolf tomaswolf added this to the 2.9.3 milestone Dec 10, 2022
tomaswolf added a commit to tomaswolf/mina-sshd that referenced this issue Dec 11, 2022
ExecutorService implements AutoCloseable in Java 19 and provides a
default method for close(). This conflicts in CloseableExecutorService,
which mixes in org.apache.sshd.common.Closeable, which has its own
default method for close().

As a minimum fix add an overrides of close() explicitly calling
the Apache MINA sshd variant of close().

Bug: apache#285
tomaswolf added a commit to tomaswolf/mina-sshd that referenced this issue Dec 11, 2022
ExecutorService implements AutoCloseable in Java 19 and provides a
default method for close(). This conflicts in CloseableExecutorService,
which mixes in org.apache.sshd.common.Closeable, which has its own
default method for close().

As a minimum fix add overrides of close() as needed, explicitly calling
the Apache MINA sshd variant of close().

Bug: apache#285
@cushon
Copy link
Contributor Author

cushon commented Dec 11, 2022

I'm still seeing a compilation error:

$ mvn clean package -Djava.sdk.version=19
...
[ERROR] /usr/local/google/home/cushon/src/mina-sshd/sshd-common/src/main/java/org/apache/sshd/common/util/threads/CloseableExecutorService.java:[37,18] close() in org.apache.sshd.common.util.threads.CloseableExecutorService clashes with close() in java.util.concurrent.ExecutorService
[ERROR]   overridden method does not throw java.io.IOException

One option might be to rethrow as UncheckedIOException to avoid the clash:

diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/threads/CloseableExecutorService.java b/sshd-common/src/main/java/org/apache/sshd/common/util/threads/CloseableExecutorService.java
index cc7a81b9..3f4bf77d 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/util/threads/CloseableExecutorService.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/util/threads/CloseableExecutorService.java
@@ -20,6 +20,7 @@
 package org.apache.sshd.common.util.threads;

 import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.time.Duration;
 import java.util.Objects;
 import java.util.concurrent.ExecutorService;
@@ -34,7 +35,11 @@ public interface CloseableExecutorService extends ExecutorService, Closeable {
     }

     @Override
-    default void close() throws IOException {
-        Closeable.super.close();
+    default void close() {
+        try {
+            Closeable.super.close();
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
     }
 }

@tomaswolf
Copy link
Member

Want to provide a pull request?

@tomaswolf tomaswolf reopened this Dec 11, 2022
cushon added a commit to cushon/mina-sshd that referenced this issue Dec 11, 2022
tomaswolf pushed a commit that referenced this issue Dec 12, 2022
@tomaswolf
Copy link
Member

Thank you, Liam!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants