From 95d3227f9d8096ea662fa3573814575813756de4 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Wed, 25 Nov 2026 00:15:19 +0100 Subject: [PATCH] Simplify building the platform state key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract the per-bundle formatting and SHA-256 hashing of getCurrentPlatformState into toStateEntry and hash helper methods, using plain concatenation instead of String.format. The resulting key is unchanged. Assisted-by: multiple AI agents and layers of automated tooling 🤖 --- .../resources/ContentDescriptionManager.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ContentDescriptionManager.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ContentDescriptionManager.java index 7cbb44cb57a..c4c28024be6 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ContentDescriptionManager.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ContentDescriptionManager.java @@ -502,15 +502,22 @@ private static String getCurrentPlatformState() { if (bundleContext == null) { return ""; //$NON-NLS-1$ } - String ID = Arrays.stream(bundleContext.getBundles()) - .map(bundle -> String.format("%d %s %s", bundle.getBundleId(), bundle.getSymbolicName(), //$NON-NLS-1$ - bundle.getVersion())) + String state = Arrays.stream(bundleContext.getBundles()) + .map(ContentDescriptionManager::toStateEntry) .sorted().collect(Collectors.joining(System.lineSeparator())); + return hash(state); + } + + private static String toStateEntry(Bundle bundle) { + return bundle.getBundleId() + " " + bundle.getSymbolicName() + " " + bundle.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ + } + + private static String hash(String value) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); //$NON-NLS-1$ - return HexFormat.of().formatHex(digest.digest(ID.getBytes(StandardCharsets.UTF_8))); + return HexFormat.of().formatHex(digest.digest(value.getBytes(StandardCharsets.UTF_8))); } catch (NoSuchAlgorithmException e) { - return Integer.toHexString(ID.hashCode()); + return Integer.toHexString(value.hashCode()); } }