Use reflection for test to fix compiling core to older Java versions

This commit is contained in:
games647
2024-05-06 09:40:07 +02:00
parent caf5188246
commit 690eabaa5e
3 changed files with 12 additions and 6 deletions

View File

@ -46,6 +46,7 @@ You can download them from here: https://ci.codemc.org/job/Games647/job/FastLogi
fastlogin.bukkit.command.premium
fastlogin.bukkit.command.cracked
fastlogin.command.premium.other
fastlogin.command.cracked.other

View File

@ -40,10 +40,8 @@
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<!-- Make Java 21 test method available in this multi-release project: Caution of breaking older systems -->
<maven.compiler.release>21</maven.compiler.release>
<!-- Still force Java 8 for the remaining project -->
<maven.compiler.release>8</maven.compiler.release>
</properties>
<name>FastLoginCore</name>

View File

@ -33,6 +33,7 @@ import org.junit.jupiter.api.condition.JRE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
@ -63,8 +64,14 @@ class AsyncSchedulerTest {
}
private static void setVirtual(AtomicBoolean virtual) {
if (Thread.currentThread().isVirtual()) {
virtual.set(true);
boolean isVirtual;
try {
isVirtual = (boolean) Thread.class.getDeclaredMethod("isVirtual").invoke(Thread.currentThread());
if (isVirtual) {
virtual.set(true);
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
}