From: Matt Corallo Date: Sat, 12 Jun 2021 16:51:02 +0000 (+0000) Subject: Avoid use of covariant return type change fns fixing backwards compat X-Git-Tag: v0.0.98.1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=efe8eb73aa5bbecd3ba98dce862dd2fc0954bf9e;p=ldk-java Avoid use of covariant return type change fns fixing backwards compat See, eg, https://jira.mongodb.org/browse/JAVA-2559. This results in errors like the following: ``` 2021-06-12 17:15:58.893 13340-13412/com.example.rnldk E/AndroidRuntime: FATAL EXCEPTION: NioPeerHandler NIO Thread Process: com.example.rnldk, PID: 13340 java.lang.NoSuchMethodError: No virtual method clear()Ljava/nio/ByteBuffer; in class Ljava/nio/ByteBuffer; or its super classes (declaration of 'java.nio.ByteBuffer' appears in /system/framework/core-oj.jar) at org.ldk.batteries.NioPeerHandler.lambda$new$0$NioPeerHandler(NioPeerHandler.java:185) at org.ldk.batteries.-$$Lambda$NioPeerHandler$f9v_DKRzmlYYXidLTlb3OtA-tVY.run(Unknown Source:2) at java.lang.Thread.run(Thread.java:764) ``` --- diff --git a/src/main/java/org/ldk/batteries/NioPeerHandler.java b/src/main/java/org/ldk/batteries/NioPeerHandler.java index f0a38282..db0fa82b 100644 --- a/src/main/java/org/ldk/batteries/NioPeerHandler.java +++ b/src/main/java/org/ldk/batteries/NioPeerHandler.java @@ -5,6 +5,7 @@ import org.ldk.structs.*; import java.io.IOException; import java.net.SocketAddress; import java.net.StandardSocketOptions; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.channels.*; @@ -182,13 +183,13 @@ public class NioPeerHandler { } } if (key.isValid() && (key.interestOps() & SelectionKey.OP_READ) != 0 && key.isReadable()) { - buf.clear(); + ((Buffer)buf).clear(); int read = ((SocketChannel) key.channel()).read(buf); if (read == -1) { this.peer_manager.socket_disconnected(peer.descriptor); key.cancel(); } else if (read > 0) { - buf.flip(); + ((Buffer)buf).flip(); byte[] read_bytes = new byte[read]; buf.get(read_bytes, 0, read); Result_boolPeerHandleErrorZ res = this.peer_manager.read_event(peer.descriptor, read_bytes);