From 5b11a84de1e4f8918b4db018b5b253bfb1e740d7 Mon Sep 17 00:00:00 2001 From: Ade Lucas Date: Tue, 20 Aug 2024 18:33:26 -0400 Subject: [PATCH] Add changelog entry and apply spotless fixes This commit adds a new entry to `CHANGELOG.md` detailing the fix for the `ClassCastException` in `DebugMetrics`. Additionally, `DebugMetricsTest.java` has been reformatted using `spotlessApply` to ensure code style consistency. These changes contribute to maintaining clear documentation and code quality in the project. Resolves: #7383 Signed-off-by: Ade Lucas --- CHANGELOG.md | 8 ++++ .../internal/methods/DebugMetricsTest.java | 42 +++++++++---------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ad5678b086..7354c4b17e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [Unreleased] + +### Fixed +- **DebugMetrics**: Fixed a `ClassCastException` occurring in `DebugMetrics` when handling nested metric structures. Previously, `Double` values within these structures were incorrectly cast to `Map` objects, leading to errors. This update allows for proper handling of both direct values and nested structures at the same level. Issue# [#7383] + +### Tests +- Added a comprehensive test case to reproduce the bug and verify the fix for the `ClassCastException` in `DebugMetrics`. This ensures that complex, dynamically nested metric structures can be handled without errors. + ## Next release ### Upcoming Breaking Changes diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugMetricsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugMetricsTest.java index c21b1a7817e..d4830cb85a7 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugMetricsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugMetricsTest.java @@ -90,32 +90,30 @@ public void shouldNestObservationsByLabel() { public void shouldHandleDoubleValuesInNestedStructureWithoutClassCastException() { // Tests fix for issue# 7383: debug_metrics method error when(metricsSystem.streamObservations()) - .thenReturn( - Stream.of( - // This creates a double value for "a" - new Observation(BLOCKCHAIN, "nested_metric", 1.0, List.of("a")), - // This attempts to create a nested structure under "a", which was previously a double - new Observation(BLOCKCHAIN, "nested_metric", 2.0, asList("a", "b")), - // This adds another level of nesting - new Observation(BLOCKCHAIN, "nested_metric", 3.0, asList("a", "b", "c")) - )); + .thenReturn( + Stream.of( + // This creates a double value for "a" + new Observation(BLOCKCHAIN, "nested_metric", 1.0, List.of("a")), + // This attempts to create a nested structure under "a", which was previously a + // double + new Observation(BLOCKCHAIN, "nested_metric", 2.0, asList("a", "b")), + // This adds another level of nesting + new Observation(BLOCKCHAIN, "nested_metric", 3.0, asList("a", "b", "c")))); assertResponse( + ImmutableMap.of( + BLOCKCHAIN.getName(), ImmutableMap.of( - BLOCKCHAIN.getName(), + "nested_metric", + ImmutableMap.of( + "a", ImmutableMap.of( - "nested_metric", ImmutableMap.of( - "a", ImmutableMap.of( - "value", 1.0, - "b", ImmutableMap.of( - "value", 2.0, - "c", 3.0 - ) - ) - ) - ) - ) - ); + "value", + 1.0, + "b", + ImmutableMap.of( + "value", 2.0, + "c", 3.0)))))); } private void assertResponse(final ImmutableMap expectedResponse) {