{"record":{"id":"119e1ec14b0fdadf","repo":"apache/shenyu","slug":"error-retrieving-system-information-e-getmessage","errorCode":null,"errorMessage":"Error retrieving system information: \" + e.getMessage()","messagePattern":"Error retrieving system information: \" \\+ e\\.getMessage\\(\\)","errorType":"exception","errorClass":"ShenyuException","httpStatus":null,"severity":"warning","filePath":"shenyu-common/src/main/java/org/apache/shenyu/common/utils/SystemInfoUtils.java","lineNumber":72,"sourceCode":"     */\n    public static String getSystemInfo() {\n        try {\n            // Get host information using OSHI\n            SystemInfo systemInfo = new SystemInfo();\n\n            // Get host information\n            OperatingSystemMXBean osBean =\n                    (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();\n            Map<String, Object> hostInfo = Map.of(\n                    ARCH, osBean.getArch(),\n                    OPERATING_SYSTEM, systemInfo.getOperatingSystem().toString(),\n                    AVAILABLE_PROCESSORS, osBean.getAvailableProcessors(),\n                    TOTAL_MEMORY_SIZE_GB, bytesToGB(osBean.getTotalMemorySize()) + GB\n            );\n            return GsonUtils.getInstance().toJson(hostInfo);\n        } catch (Exception e) {\n            // Handle any exceptions that may occur\n            throw new ShenyuException(\"Error retrieving system information: \" + e.getMessage());\n        }\n    }\n\n    /**\n     * Bytes to gb double.\n     *\n     * @param bytesValue the bytes value\n     * @return the double\n     */\n    private static double bytesToGB(final long bytesValue) {\n        return BigDecimal.valueOf(bytesValue / (double) BYTES_IN_GB)\n                .setScale(DECIMAL_PLACES, ROUNDING_MODE)\n                .doubleValue();\n    }\n}\n","sourceCodeStart":54,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-common/src/main/java/org/apache/shenyu/common/utils/SystemInfoUtils.java#L54-L88","documentation":"SystemInfoUtils.getSystemInfo collects OS/Java runtime metrics (processors, memory) via OperatingSystemMXBean and returns them as JSON. Any exception during metric collection is wrapped in ShenyuException 'Error retrieving system information: <message>'.","triggerScenarios":"Calling getSystemInfo on a JVM/platform where the MXBean methods (getTotalMemorySize, etc.) are unavailable or throw, or when JSON serialization of the collected map fails.","commonSituations":"Running on an older JDK where the OS bean method names differ (com.sun.management.OperatingSystemMXBean API changes); restricted containers blocking MXBean access; custom MBean server setups.","solutions":["Upgrade/verify the JDK supports com.sun.management.OperatingSystemMXBean methods used (Java 14+ renamed get{Total,Free}PhysicalMemorySize variants).","Catch and degrade gracefully: return partial system info instead of throwing.","Run on a supported platform/JDK combination matching ShenYu's requirements (Java 17).","Inspect the wrapped message (e.getMessage) to identify the specific MXBean call that failed."],"exampleFix":"// before\nString info = SystemInfoUtils.getSystemInfo(); // may throw\n// after\nString info;\ntry {\n    info = SystemInfoUtils.getSystemInfo();\n} catch (Exception e) {\n    LOG.warn(\"system info unavailable: {}\", e.getMessage());\n    info = \"{}\";\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { String info = SystemInfoUtils.getSystemInfo(); } catch (ShenyuException e) { LOG.warn(\"system info unavailable: {}\", e.getMessage()); info = \"{}\"; }","preventionTips":["Run on a JDK matching ShenYu requirements (Java 17)","Return degraded/empty JSON instead of failing monitoring calls","Wrap MXBean access in feature detection","Test on containerized and bare-metal environments"],"tags":["system-info","mxbean","reflection","jvm"],"backgroundTag":"unsupported-platform","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}