fixed bug in jvm checker (#4845)

This commit is contained in:
Jake Potrebic 2020-12-04 19:58:24 -08:00
parent 08835cda45
commit 1023360683

View File

@ -4,36 +4,35 @@ Date: Wed, 2 Dec 2020 21:58:45 -0800
Subject: [PATCH] Add warning for servers not running on Java 11 Subject: [PATCH] Add warning for servers not running on Java 11
diff --git a/src/main/java/com/destroystokyo/paper/util/PaperJvmChecker.java b/src/main/java/com/destroystokyo/paper/util/PaperJvmChecker.java diff --git a/src/main/java/io/papermc/paper/util/PaperJvmChecker.java b/src/main/java/io/papermc/paper/util/PaperJvmChecker.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/util/PaperJvmChecker.java +++ b/src/main/java/io/papermc/paper/util/PaperJvmChecker.java
@@ -0,0 +0,0 @@ @@ -0,0 +0,0 @@
+package com.destroystokyo.paper.util; +package io.papermc.paper.util;
+ +
+import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Logger;
+ +
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class PaperJvmChecker { +public class PaperJvmChecker {
+ +
+ private static int getJvmVersion() { + private static int getJvmVersion() {
+ String javaVersion = System.getProperty("java.version"); + String javaVersion = System.getProperty("java.version");
+ int dotIndex = javaVersion.indexOf('.'); + final Matcher matcher = Pattern.compile("(?:1\\.)?(\\d+)").matcher(javaVersion);
+ + if (!matcher.find()) {
+ if (javaVersion.startsWith("1.")) { + LogManager.getLogger().warn("Failed to determine Java version; Could not parse: {}", javaVersion);
+ // For Java 8 and below, trim off the 1. prefix + return -1;
+ javaVersion = javaVersion.substring(2);
+ dotIndex = javaVersion.indexOf('.');
+ } + }
+ +
+ final int endIndex = dotIndex == -1 ? javaVersion.length() : dotIndex; + final String version = matcher.group(1);
+ final String version = javaVersion.substring(0, endIndex);
+
+ try { + try {
+ return Integer.parseInt(version); + return Integer.parseInt(version);
+ } catch (final NumberFormatException e) { + } catch (final NumberFormatException e) {
+ LogManager.getLogger().warn("Failed to determine Java version; Could not parse {}", version, e); + LogManager.getLogger().warn("Failed to determine Java version; Could not parse {} from {}", version, javaVersion, e);
+ return -1; + return -1;
+ } + }
+ } + }
@ -63,12 +62,19 @@ diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java --- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -0,0 +0,0 @@ import org.bukkit.craftbukkit.Main;
import org.bukkit.event.server.ServerLoadEvent;
// CraftBukkit end
import co.aikar.timings.MinecraftTimings; // Paper
+import io.papermc.paper.util.PaperJvmChecker; // Paper
import org.spigotmc.SlackActivityAccountant; // Spigot
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements IMojangStatistics, ICommandListener, AutoCloseable {
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
LOGGER.info("Done ({})! For help, type \"help\"", doneTime); LOGGER.info("Done ({})! For help, type \"help\"", doneTime);
// Paper end // Paper end
+ com.destroystokyo.paper.util.PaperJvmChecker.checkJvm(); // Paper jvm version nag + PaperJvmChecker.checkJvm(); // Paper jvm version nag
+
org.spigotmc.WatchdogThread.tick(); // Paper org.spigotmc.WatchdogThread.tick(); // Paper
org.spigotmc.WatchdogThread.hasStarted = true; // Paper org.spigotmc.WatchdogThread.hasStarted = true; // Paper
Arrays.fill( recentTps, 20 ); Arrays.fill( recentTps, 20 );