Skip to content

Commit

Permalink
test: rmi: Fix compatibility with GraalVM 17.0.9 behavior
Browse files Browse the repository at this point in the history
While testing GraalVM 17.0.9, selftest failed with a different exception
than expected (instead of a NoSuchObjectException, we get an
IllegalArgumentException with a NoSuchMethodException cause).

Handle this case gracefully to reduce false positive errors in selftest.
  • Loading branch information
kohlschuetter committed Sep 13, 2024
1 parent fd128e4 commit f7bc7ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.newsclub.net.unix.rmi;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.rmi.NoSuchObjectException;
Expand Down Expand Up @@ -60,14 +60,19 @@ public void testRemoteCloseableWithACloseableThing() throws IOException, NotBoun
remoteCloseable.close();
assertEquals(1, svc.remoteCloseableThingNumberOfCloseCalls(IsCloseable.class));

assertThrows(NoSuchObjectException.class, () -> {
remoteCloseable.close();
});
remoteCloseable.close();
fail("Should have thrown an exception");
}
} catch (NoSuchObjectException e) {
// expected — since the object was forcibly closed above, it was unexported already.
// ideally, RMI could gracefully handle calling #close() on an proxy that points to an
// unexported object.
} catch (IllegalArgumentException e) {
if (e.getCause() instanceof NoSuchMethodException) {
// observed with GraalVM 17.0.9; see java.rmi.server.RemoteObjectInvocationHandler
} else {
throw e;
}
}
assertEquals(1, svc.remoteCloseableThingNumberOfCloseCalls(IsCloseable.class));

Expand Down Expand Up @@ -99,13 +104,18 @@ public void testRemoteCloseableWithANotCloseableThing() throws IOException, NotB
remoteCloseable.close();
assertEquals(0, svc.remoteCloseableThingNumberOfCloseCalls(NotCloseable.class));

assertThrows(NoSuchObjectException.class, () -> {
remoteCloseable.close();
});
remoteCloseable.close();
fail("Should have thrown an exception");
} catch (NoSuchObjectException e) {
// expected — since the object was forcibly closed above, it was unexported already.
// ideally, RMI could gracefully handle calling #close() on an proxy that points to an
// unexported object.
} catch (IllegalArgumentException e) {
if (e.getCause() instanceof NoSuchMethodException) {
// observed with GraalVM 17.0.9; see java.rmi.server.RemoteObjectInvocationHandler
} else {
throw e;
}
}
assertEquals(0, svc.remoteCloseableThingNumberOfCloseCalls(NotCloseable.class));

Expand Down
1 change: 1 addition & 0 deletions src/site/markdown/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ artifact (`<type>pom</type>`); see [Add junixsocket to your project](dependency.
- Fix left-over temporary library files on Windows
- Fix duplicate file descriptors being received sporadically for non-blocking sockets and upon error
- Fix a flaky selftest when VSOCK is not supported
- Fix a flaky selftest with GraalvM 17
- Improve interoperability with exotic Linux/Java combinations
- Add support for loongarch64 Linux
- Add more tests
Expand Down

0 comments on commit f7bc7ed

Please sign in to comment.