]> git.bitcoin.ninja Git - ldk-java/commitdiff
Avoid use of covariant return type change fns fixing backwards compat v0.0.98.1
authorMatt Corallo <git@bluematt.me>
Sat, 12 Jun 2021 16:51:02 +0000 (16:51 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 12 Jun 2021 16:59:19 +0000 (16:59 +0000)
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)
```

src/main/java/org/ldk/batteries/NioPeerHandler.java

index f0a38282d04d7f7fcaf74c8818bbebdf9328fe58..db0fa82b130e7ae7dd6635145d5112bc8b6ebb90 100644 (file)
@@ -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);