mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[build] Java 25 support (#8775)
Commands v3 had a few changes due to the upgrade: - Java 24 removed the Pinned: MONITOR IllegalStateException when yielding in a synchronized block, so we no longer need to special case for it - Lambda method name generation was tweaked, requiring tests to be updated - Bazel java_rules needed to be bumped to support Java 25 Closes #8425
This commit is contained in:
@@ -48,24 +48,7 @@ public final class Coroutine {
|
||||
public boolean yield() {
|
||||
requireMounted();
|
||||
|
||||
try {
|
||||
return m_backingContinuation.yield();
|
||||
} catch (IllegalStateException e) {
|
||||
if ("Pinned: MONITOR".equals(e.getMessage())) {
|
||||
// Raised when a continuation yields inside a synchronized block or method:
|
||||
// https://github.com/openjdk/jdk/blob/jdk-21%2B35/src/java.base/share/classes/jdk/internal/vm/Continuation.java#L396-L402
|
||||
// Note: Not a thing in Java 24+
|
||||
// Rethrow with an error message that's more helpful for our users
|
||||
throw new IllegalStateException(
|
||||
"Coroutine.yield() cannot be called inside a synchronized block or method. "
|
||||
+ "Consider using a Lock instead of synchronized, "
|
||||
+ "or rewrite your code to avoid locks and mutexes altogether.",
|
||||
e);
|
||||
} else {
|
||||
// rethrow
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return m_backingContinuation.yield();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,13 +58,8 @@ class CoroutineTest extends CommandTestBase {
|
||||
.named("Yield In Synchronized Block");
|
||||
|
||||
m_scheduler.schedule(yieldInSynchronized);
|
||||
|
||||
var error = assertThrows(IllegalStateException.class, m_scheduler::run);
|
||||
assertEquals(
|
||||
"Coroutine.yield() cannot be called inside a synchronized block or method. "
|
||||
+ "Consider using a Lock instead of synchronized, "
|
||||
+ "or rewrite your code to avoid locks and mutexes altogether.",
|
||||
error.getMessage());
|
||||
m_scheduler.run();
|
||||
assertEquals(1, i.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -88,8 +88,8 @@ class SchedulerErrorHandlingTests extends CommandTestBase {
|
||||
|
||||
// user code trace for where the command was scheduled (the `.onTrue()` line)
|
||||
assertEquals("=== Command Binding Trace ===", stackTrace[nestedIndex + 2].getClassName());
|
||||
assertEquals("lambda$nestedErrorDetection$4", stackTrace[nestedIndex + 3].getMethodName());
|
||||
assertEquals("lambda$nestedErrorDetection$5", stackTrace[nestedIndex + 4].getMethodName());
|
||||
assertEquals("lambda$nestedErrorDetection$1", stackTrace[nestedIndex + 3].getMethodName());
|
||||
assertEquals("lambda$nestedErrorDetection$0", stackTrace[nestedIndex + 4].getMethodName());
|
||||
assertEquals("nestedErrorDetection", stackTrace[nestedIndex + 5].getMethodName());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user