{"record":{"id":"24ad1cc543c61380","repo":"NationalSecurityAgency/ghidra","slug":"error-constructing-dependent-service-via","errorCode":null,"errorMessage":"Error constructing dependent service via {}","messagePattern":"Error constructing dependent service via (.+?)","errorType":"exception","errorClass":"ServiceConstructionException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/ProposedUtils/src/main/java/generic/depends/DependentServiceConstructor.java","lineNumber":50,"sourceCode":"\t\t}\n\t\tthis.cls = cls;\n\t\tthis.method = method;\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\tT construct(Object obj, Map<Class<?>, Object> dependencies)\n\t\t\tthrows ServiceConstructionException {\n\t\tList<Object> params = new ArrayList<>(method.getParameterCount());\n\t\tfor (Class<?> pType : method.getParameterTypes()) {\n\t\t\tObject p = dependencies.get(pType);\n\t\t\tassert p != null;\n\t\t\tparams.add(p);\n\t\t}\n\t\ttry {\n\t\t\treturn (T) method.invoke(obj, params.toArray());\n\t\t}\n\t\tcatch (InvocationTargetException e) {\n\t\t\tthrow new ServiceConstructionException(\n\t\t\t\t\"Error constructing dependent service via \" + method, e.getCause());\n\t\t}\n\t\tcatch (IllegalAccessException | IllegalArgumentException e) {\n\t\t\tthrow new AssertionError(e);\n\t\t}\n\t}\n}\n","sourceCodeStart":32,"sourceCodeEnd":58,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/ProposedUtils/src/main/java/generic/depends/DependentServiceConstructor.java#L32-L58","documentation":"Thrown by DependentServiceConstructor.construct() when invoking the @DependentService factory method raises an exception (caught as InvocationTargetException). The original cause is unwrapped and wrapped in a ServiceConstructionException, preserving the offending method in the message. This is a runtime failure inside the user-supplied factory, not a wiring error.","triggerScenarios":"A @DependentService method throws a NullPointerException, an IOException, an IllegalStateException, or any exception during construction. A dependency passed into the method is in an invalid state. A required resource (file, network, config) is unavailable when the factory runs.","commonSituations":"Factory methods that open files or databases at construction time; null dependencies due to incomplete registration; constructor logic that validates configuration and rejects bad state; service initialization ordering where a prerequisite is not yet ready.","solutions":["Inspect the wrapped cause (ServiceConstructionException.getCause()) to find the real failure and the stack location.","Fix the root cause inside the factory method (null guard, resource availability, argument validation).","Ensure all dependencies the method declares as parameters were themselves constructed successfully before this service.","Add logging/defensive checks in the factory so failures are explicit rather than generic NPEs."],"exampleFix":"// before\n@DependentService\npublic MyService build(Config cfg) {\n  return new MyService(cfg.getPath().toFile()); // NPE if getPath()==null\n}\n\n// after\n@DependentService\npublic MyService build(Config cfg) {\n  java.nio.file.Path p = Objects.requireNonNull(cfg.getPath(), \"config path\");\n  return new MyService(p.toFile());\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  DependentServiceResolver.inject(obj);\n} catch (ServiceConstructionException e) {\n  Throwable cause = e.getCause();\n  Msg.error(this, \"Service construction failed via \" + e.getMessage(), cause);\n  // handle or rethrow after enriching context\n}","preventionTips":["Make factory methods fail with clear, typed exceptions rather than NPEs.","Validate dependencies (non-null, correct state) at the top of each factory.","Log the unwrapped cause so the real failure site is visible."],"tags":["ghidra","dependency-injection","runtime-failure","factory"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}