java-topology/tools/tickets/defects/javac-0002a.md
russell@unturf.com db29a08762 undefect. CWE-407 — 92 sites, 42 ecosystems
B&W print-friendly diagrams + tinkerpop-0001 + wave-3 proof sections.
Squash of 94 local commits onto remote master.
2026-03-26 19:48:18 -04:00

1.2 KiB

id repo severity status created
javac-0002a openjdk HIGH patched 2026-03-23

Defect

File: src/jdk.compiler/.../javac/comp/Infer.java:1850 Pattern: ArrayList.contains in findNode Complexity: O(N²) Language: Java

Description

findNode is called during type inference graph construction to check whether a node is already present in the node list. The check is performed using ArrayList.contains, which performs a full linear scan. Because findNode is called once per inference variable during graph construction, and each call scans up to N existing nodes, the total cost of node lookup is O(N²) in the number of inference variables.

Fix

Replace: nodes.contains(node) With: nodeSet.contains(node) Data structure change: ArrayList<Node> nodes → HashSet<Node> nodeSet + ArrayList<Node> nodes

Work required

  • Patch in defects/javac/patch/
  • Unit test — asserts exact operation counts before/after (in defects/javac/unit/)
  • Integration test (in defects/javac/integration/)
  • Benchmark — before/after on V=100,200,400,800 (in defects/javac/bench/)
  • White paper section