{"record":{"id":"44dc4fea52698198","repo":"NationalSecurityAgency/ghidra","slug":"could-not-resolve-required-parameter-for-next-in","errorCode":null,"errorMessage":"Could not resolve required parameter for next in: {}. Note: it may be a circular dependency.","messagePattern":"Could not resolve required parameter for next in: (.+?)\\. Note: it may be a circular dependency\\.","errorType":"exception","errorClass":"UnsatisfiedParameterException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/ProposedUtils/src/main/java/generic/depends/DependentServiceResolver.java","lineNumber":117,"sourceCode":"\t\t\t}\n\t\t\tClass<?> fCls = f.getType();\n\t\t\tfieldsByClass.computeIfAbsent(fCls, c -> new HashSet<>()).add(f);\n\t\t\tf.setAccessible(true);\n\t\t}\n\t}\n\n\tprivate void compile() throws UnsatisfiedParameterException, UnsatisfiedFieldsException {\n\t\tSet<Class<?>> missing = new HashSet<>(fieldsByClass.keySet());\n\t\tmissing.removeAll(constructors.keySet());\n\t\tif (!missing.isEmpty()) {\n\t\t\tthrow new UnsatisfiedFieldsException(missing);\n\t\t}\n\t\tSet<Class<?>> unordered = new HashSet<>(constructors.keySet());\n\t\twhile (!unordered.isEmpty()) {\n\t\t\tSet<Class<?>> forRound = new HashSet<>(unordered);\n\t\t\tforRound.removeAll(depsByDependents.keySet());\n\t\t\tif (forRound.isEmpty()) {\n\t\t\t\tthrow new UnsatisfiedParameterException(unordered);\n\t\t\t}\n\t\t\tfor (Class<?> ready : forRound) {\n\t\t\t\tMethod m = constructors.get(ready);\n\t\t\t\tunordered.remove(ready);\n\t\t\t\tordered.add(new DependentServiceConstructor<>(ready, m));\n\t\t\t\tfor (Iterator<Set<Class<?>>> iterator =\n\t\t\t\t\tdepsByDependents.values().iterator(); iterator.hasNext();) {\n\t\t\t\t\tSet<Class<?>> deps = iterator.next();\n\t\t\t\t\tdeps.remove(ready);\n\t\t\t\t\tif (deps.isEmpty()) {\n\t\t\t\t\t\titerator.remove();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tassert ordered.size() == constructors.size();\n\t}\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/ProposedUtils/src/main/java/generic/depends/DependentServiceResolver.java#L99-L135","documentation":"Thrown by DependentServiceResolver.compile() as an UnsatisfiedParameterException when the topological sort of constructors stalls: in a given round no constructor has all its parameter dependencies satisfied, meaning the remaining set is mutually/circularly dependent. The message explicitly notes it may be a circular dependency and lists the unresolved types.","triggerScenarios":"Service A's factory takes a B, and service B's factory takes an A (direct cycle). Longer cycles (A->B->C->A). A factory parameter type that is never produced by any factory, so the dependency can never be cleared. A self-dependent method that takes its own return type as a parameter.","commonSituations":"Two services that legitimately reference each other during construction; an unregistered dependency type masquerading as a cycle; refactoring that introduces a new parameter creating an inadvertent cycle.","solutions":["Break the cycle by removing one direction of the dependency (e.g. use field injection or a setter for one side).","Ensure every parameter type of every @DependentService method is itself produced by some @DependentService method.","Inspect the exception's unresolved set and trace each type's parameters to find the cycle or the missing producer.","If the cycle is inherent, restructure so one service is constructed lazily or via a factory that does not require the other at construction time."],"exampleFix":"// before -- cycle\n@DependentService public A buildA(B b) { ... }\n@DependentService public B buildB(A a) { ... }\n\n// after -- break by removing parameter from one side\n@DependentService public A buildA() { ... }\n@DependentService public B buildB(A a) { ... }","handlingStrategy":"validation","validationCode":"// build dependency graph and detect cycles before invoking resolver\nMap<Class<?>, Set<Class<?>>> deps = collectParameterDeps(cls);\nif (hasCycle(deps)) {\n  throw new IllegalStateException(\"Circular dependency among services: \" + cycle);\n}","typeGuard":null,"tryCatchPattern":"try {\n  DependentServiceResolver.get(cls);\n} catch (UnsatisfiedParameterException e) {\n  Msg.error(this, \"Unresolvable (circular?) dependencies: \" + e.getUnresolved());\n}","preventionTips":["Avoid bidirectional construction-time dependencies between two services.","Ensure every parameter type has a producer.","Use field/setter injection to break cycles."],"tags":["ghidra","dependency-injection","circular-dependency","topological-sort"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}