From 1adadc788266bfa33896f28656720941919a1ad0 Mon Sep 17 00:00:00 2001 From: Thomas Stuefe Date: Thu, 5 Jul 2018 11:56:19 +0200 Subject: [PATCH] 8206243: java -XshowSettings fails if memory.limit_in_bytes overflows LONG.max Reviewed-by: dholmes, bobv --- .../jdk/internal/platform/cgroupv1/SubSystem.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/SubSystem.java b/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/SubSystem.java index b010a34df08..7d2a045e253 100644 --- a/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/SubSystem.java +++ b/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/SubSystem.java @@ -27,6 +27,7 @@ package jdk.internal.platform.cgroupv1; import java.io.BufferedReader; import java.io.IOException; +import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -100,11 +101,20 @@ public class SubSystem { public static long getLongValue(SubSystem subsystem, String parm) { String strval = getStringValue(subsystem, parm); + long retval = 0; if (strval == null) return 0L; - long retval = Long.parseLong(strval); - + try { + retval = Long.parseLong(strval); + } catch (NumberFormatException e) { + // For some properties (e.g. memory.limit_in_bytes) we may overflow the range of signed long. + // In this case, return Long.max + BigInteger b = new BigInteger(strval); + if (b.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) { + return Long.MAX_VALUE; + } + } return retval; }