Skip to content

Commit 060d0bd

Browse files
improve the detection of immutable config maps
1 parent 411d953 commit 060d0bd

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

superstream-clients/src/main/java/ai/superstream/agent/KafkaProducerInterceptor.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,23 @@ public static void onEnter(@Advice.AllArguments Object[] args) {
132132
boolean immutableConfigDetected = false;
133133
java.util.Map<String,Object> immutableOriginalMap = null;
134134
for (Object arg : args) {
135-
if (arg instanceof java.util.Map && arg.getClass().getName().contains("UnmodifiableMap")) {
136-
immutableConfigDetected = true;
135+
if (arg instanceof java.util.Map) {
137136
@SuppressWarnings("unchecked")
138-
java.util.Map<String,Object> tmp = (java.util.Map<String,Object>) arg;
139-
immutableOriginalMap = tmp;
140-
break;
137+
java.util.Map<String,Object> testMap = (java.util.Map<String,Object>) arg;
138+
139+
// Skip empty maps as they might be immutable but don't matter for optimization
140+
if (!testMap.isEmpty()) {
141+
try {
142+
String testKey = "__superstream_immutable_test_" + System.nanoTime();
143+
testMap.put(testKey, "test");
144+
testMap.remove(testKey);
145+
} catch (UnsupportedOperationException | IllegalStateException e) {
146+
// Map is immutable
147+
immutableConfigDetected = true;
148+
immutableOriginalMap = testMap;
149+
break;
150+
}
151+
}
141152
}
142153
}
143154

0 commit comments

Comments
 (0)