diff --git a/classpath/java-nio.cpp b/classpath/java-nio.cpp index 0eb7dda3a8..0a8a1bcf36 100644 --- a/classpath/java-nio.cpp +++ b/classpath/java-nio.cpp @@ -115,12 +115,17 @@ throwIOException(JNIEnv* e, const char* s) throwNew(e, "java/io/IOException", s); } -void -throwIOException(JNIEnv* e, jbyteArray a) +void throwIOException(JNIEnv* e, jbyteArray a) { - jbyte* s = static_cast(e->GetPrimitiveArrayCritical(a, 0)); - throwIOException(e, reinterpret_cast(s)); - e->ReleasePrimitiveArrayCritical(a, s, 0); + size_t length = e->GetArrayLength(a); + uint8_t* buf = static_cast(allocate(e, length)); + if (buf) { + e->GetByteArrayRegion(a, 0, length, reinterpret_cast(buf)); + throwIOException(e, reinterpret_cast(buf)); + free(buf); + } else { + return; + } } void diff --git a/src/avian/machine.h b/src/avian/machine.h index 21ca414af6..935f0eade3 100644 --- a/src/avian/machine.h +++ b/src/avian/machine.h @@ -1841,6 +1841,7 @@ allocate(Thread* t, unsigned sizeInBytes, bool objectMask) { return allocate2(t, sizeInBytes, objectMask); } else { + assert(t, t->criticalLevel == 0); return allocateSmall(t, sizeInBytes); } } diff --git a/test/Sockets.java b/test/Sockets.java new file mode 100644 index 0000000000..9bce0e036e --- /dev/null +++ b/test/Sockets.java @@ -0,0 +1,33 @@ +import java.net.SocketAddress; +import java.net.InetSocketAddress; +import java.nio.channels.SocketChannel; +import java.io.IOException; + +public class Sockets { + private static void expect(boolean v) { + if (! v) throw new RuntimeException(); + } + + public static void testFailedBind() throws Exception { + final String Hostname = "localhost"; + final int Port = 22046; // hopefully this port is unused + final SocketAddress Address = new InetSocketAddress(Hostname, Port); + final byte[] Message = "hello, world!".getBytes(); + + SocketChannel out = SocketChannel.open(); + try { + try { + out.connect(Address); + expect(false); + } catch(IOException e) { + // We're good. This previously triggered a vm assert, rather than an exception + } + } finally { + out.close(); + } + } + + public static void main(String[] args) throws Exception { + testFailedBind(); + } +}