Skip to content

Commit 3a6c5fb

Browse files
Flossyclaude
andcommitted
fix: Throw exception on deserialization failure in getAllApplicationDescriptors
Fixes #197 Changed HazelcastStateStore.getAllApplicationDescriptors() to throw RuntimeException when any descriptor fails to deserialize, instead of silently skipping failed descriptors and returning incomplete data. Changes: - Throw RuntimeException with clear message when deserialization fails - Include application ID in error message - Indicate cluster state may be corrupted - Updated existing test to expect the exception - Ensures callers are always aware of failures This prevents silent data loss and ensures cluster state integrity. Consistent with getApplicationDescriptor() behavior. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent eba7a73 commit 3a6c5fb

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

jplatform-cluster/src/main/java/org/flossware/jplatform/cluster/HazelcastStateStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public ApplicationDescriptor getApplicationDescriptor(String applicationId) {
171171
* Creates a local snapshot and deserializes all descriptors.
172172
*
173173
* @return a map of application ID to descriptor
174+
* @throws RuntimeException if any descriptor fails to deserialize
174175
*/
175176
@Override
176177
public Map<String, ApplicationDescriptor> getAllApplicationDescriptors() {
@@ -183,6 +184,9 @@ public Map<String, ApplicationDescriptor> getAllApplicationDescriptors() {
183184
result.put(entry.getKey(), descriptor);
184185
} catch (Exception e) {
185186
logger.error("Failed to deserialize descriptor for: {}", entry.getKey(), e);
187+
throw new RuntimeException(
188+
"Failed to deserialize application descriptor for " + entry.getKey() +
189+
" - cluster state may be corrupted", e);
186190
}
187191
}
188192

jplatform-cluster/src/test/java/org/flossware/jplatform/cluster/HazelcastStateStoreTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void testGetAllApplicationDescriptors() {
206206
}
207207

208208
@Test
209-
@DisplayName("Should skip invalid descriptors in getAllApplicationDescriptors")
209+
@DisplayName("Should throw RuntimeException when encountering invalid JSON")
210210
void testGetAllApplicationDescriptorsWithInvalid() {
211211
// Given
212212
Map<String, String> jsonMap = new HashMap<>();
@@ -216,13 +216,12 @@ void testGetAllApplicationDescriptorsWithInvalid() {
216216

217217
when(mockDescriptorMap.entrySet()).thenReturn(jsonMap.entrySet());
218218

219-
// When
220-
Map<String, ApplicationDescriptor> descriptors = stateStore.getAllApplicationDescriptors();
219+
// When / Then
220+
RuntimeException exception = assertThrows(RuntimeException.class,
221+
() -> stateStore.getAllApplicationDescriptors());
221222

222-
// Then
223-
assertEquals(1, descriptors.size());
224-
assertTrue(descriptors.containsKey("app1"));
225-
assertFalse(descriptors.containsKey("app2"));
223+
assertTrue(exception.getMessage().contains("Failed to deserialize application descriptor"));
224+
assertTrue(exception.getMessage().contains("cluster state may be corrupted"));
226225
}
227226

228227
@Test

0 commit comments

Comments
 (0)