Skip to content

Commit d3c0452

Browse files
aksOpsclaude
andcommitted
fix: ensure mutable properties map before setting file_type on nodes
Some nodes are created with immutable Map.of() (e.g., inventory nodes with Map.of("minified", true)). Calling put("file_type", ...) on these throws UnsupportedOperationException. Fix: ensureMutableProperties() helper wraps immutable maps in LinkedHashMap before mutation. Applied at both file_type assignment locations in Analyzer.java. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d3b642b commit d3c0452

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/main/java/io/github/randomcodespace/iq/analyzer/Analyzer.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ DetectorResult analyzeFileWithRegistry(DiscoveredFile file, Path repoPath,
13001300
if (moduleName != null && (node.getModule() == null || node.getModule().isEmpty())) {
13011301
node.setModule(moduleName);
13021302
}
1303-
node.getProperties().put("file_type", fileTypeStr);
1303+
ensureMutableProperties(node).put("file_type", fileTypeStr);
13041304
}
13051305

13061306
return DetectorResult.of(allNodes, allEdges);
@@ -1508,7 +1508,7 @@ DetectorResult analyzeFile(DiscoveredFile file, Path repoPath, DetectorRegistry
15081508
if (moduleName != null && (node.getModule() == null || node.getModule().isEmpty())) {
15091509
node.setModule(moduleName);
15101510
}
1511-
node.getProperties().put("file_type", fileTypeStr);
1511+
ensureMutableProperties(node).put("file_type", fileTypeStr);
15121512
}
15131513

15141514
return DetectorResult.of(allNodes, allEdges);
@@ -1626,6 +1626,24 @@ private String getGitHead(Path repoPath) {
16261626
/**
16271627
* Read file content and compute snippet. Returns null on error or for binary files.
16281628
*/
1629+
/**
1630+
* Ensure a node's properties map is mutable. Some nodes are created with
1631+
* immutable Map.of() which throws UnsupportedOperationException on put().
1632+
*/
1633+
private static Map<String, Object> ensureMutableProperties(CodeNode node) {
1634+
Map<String, Object> props = node.getProperties();
1635+
try {
1636+
// Test mutability — HashMap/LinkedHashMap will not throw
1637+
props.put("_test", null);
1638+
props.remove("_test");
1639+
return props;
1640+
} catch (UnsupportedOperationException e) {
1641+
var mutable = new java.util.LinkedHashMap<>(props);
1642+
node.setProperties(mutable);
1643+
return mutable;
1644+
}
1645+
}
1646+
16291647
private static String computeSnippetFromFile(Path absPath, FileClassifier.FileType fileType) {
16301648
if (fileType == FileClassifier.FileType.BINARY) return null;
16311649
try {

0 commit comments

Comments
 (0)