From 4dfcc944e5d0cb19c5f060d30ebe401e04e4e13f Mon Sep 17 00:00:00 2001 From: Ben Evans Date: Mon, 7 Oct 2024 14:29:22 +0200 Subject: [PATCH] RC: Fix setup of jvm.args for 1.0.1 messages (#267) --- .../insights/reports/AbstractTopLevelReportBase.java | 2 +- api/src/main/java/com/redhat/insights/reports/Utils.java | 9 +-------- .../java/com/redhat/insights/TestTopLevelReport.java | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/com/redhat/insights/reports/AbstractTopLevelReportBase.java b/api/src/main/java/com/redhat/insights/reports/AbstractTopLevelReportBase.java index 09af29f..e4f7846 100644 --- a/api/src/main/java/com/redhat/insights/reports/AbstractTopLevelReportBase.java +++ b/api/src/main/java/com/redhat/insights/reports/AbstractTopLevelReportBase.java @@ -179,7 +179,7 @@ public void generateReport(Filtering masking) { RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); List inputArguments = fixInputArguments(runtimeMXBean.getInputArguments()); - options.put("jvm.args", inputArguments); + options.put("jvm.args", String.join(" ", inputArguments)); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); diff --git a/api/src/main/java/com/redhat/insights/reports/Utils.java b/api/src/main/java/com/redhat/insights/reports/Utils.java index 3ab2d93..e94bd52 100644 --- a/api/src/main/java/com/redhat/insights/reports/Utils.java +++ b/api/src/main/java/com/redhat/insights/reports/Utils.java @@ -1,10 +1,7 @@ /* Copyright (C) Red Hat 2023-2024 */ package com.redhat.insights.reports; -import static java.util.Collections.emptyMap; - import java.util.ArrayList; -import java.util.List; import java.util.Map; public final class Utils { @@ -12,11 +9,7 @@ private Utils() {} @SuppressWarnings("unchecked") public static Map defaultMasking(final Map inArgs) { - List jvmArgs = new ArrayList<>(); - List args = (List) (inArgs.getOrDefault("jvm.args", emptyMap())); - for (String arg : args) { - jvmArgs.add(sanitizeJavaParameters(arg)); - } + String jvmArgs = sanitizeJavaParameters((String) (inArgs.getOrDefault("jvm.args", ""))); inArgs.put("jvm.args", jvmArgs); String command = (String) inArgs.getOrDefault("java.command", ""); inArgs.put("java.command", sanitizeJavaParameters(command)); diff --git a/api/src/test/java/com/redhat/insights/TestTopLevelReport.java b/api/src/test/java/com/redhat/insights/TestTopLevelReport.java index 2b0cc6a..6cb9963 100644 --- a/api/src/test/java/com/redhat/insights/TestTopLevelReport.java +++ b/api/src/test/java/com/redhat/insights/TestTopLevelReport.java @@ -326,7 +326,7 @@ public void testReportSanitization() throws IOException { Map basicReport = (Map) parseReport(report).get("basic"); assertEquals( - sanitizedJvmArgs, + String.join(" ", sanitizedJvmArgs.toArray(new String[0])), basicReport.get("jvm.args"), "The \"jvm.args\" property in the basic report should be properly sanitized."); assertEquals(