Skip to content

Commit

Permalink
Avoid use of covariant return type change fns fixing backwards compat
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
TheBlueMatt committed Jun 12, 2021
1 parent 4adc27e commit 7bd26cc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/ldk/batteries/NioPeerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.net.SocketAddress;
import java.net.StandardSocketOptions;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.*;

Expand Down Expand Up @@ -182,13 +183,13 @@ public NioPeerHandler(PeerManager manager) throws IOException {
}
}
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);
Expand Down

0 comments on commit 7bd26cc

Please sign in to comment.