{"record":{"id":"af97c693cb29f042","repo":"apache/maven","slug":"unable-to-inject-field-resolution-getfield-af97c6","errorCode":null,"errorMessage":"Unable to inject field '${resolution.getField()}' annotated with @Dependencies","messagePattern":"Unable to inject field '(.+?)' annotated with @Dependencies","errorType":"exception","errorClass":"PluginConfigurationException","httpStatus":null,"severity":"error","filePath":"impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java","lineNumber":672,"sourceCode":"                DependencyResolverResult res = sessionV4\n                        .getService(DependencyResolver.class)\n                        .collect(sessionV4, project, PathScope.MAIN_RUNTIME);\n                if (field.getType() == DependencyResolverResult.class) {\n                    result = res;\n                } else if (field.getType() == Node.class) {\n                    result = res.getRoot();\n                }\n            }\n            if (result == null) {\n                throw new PluginConfigurationException(\n                        pluginDescriptor,\n                        \"Unable to inject field '\" + resolution.getField()\n                                + \"' annotated with @Dependencies. Unsupported type \" + field.getGenericType());\n            }\n            try {\n                field.set(mojo, result);\n            } catch (IllegalAccessException e) {\n                throw new PluginConfigurationException(\n                        pluginDescriptor,\n                        \"Unable to inject field '\" + resolution.getField() + \"' annotated with @Dependencies\",\n                        e);\n            }\n        }\n\n        return mojo;\n    }\n\n    private <T> T loadV3Mojo(\n            Class<T> mojoInterface,\n            MavenSession session,\n            MojoExecution mojoExecution,\n            MojoDescriptor mojoDescriptor,\n            PluginDescriptor pluginDescriptor,\n            ClassRealm pluginRealm)\n            throws PluginContainerException, PluginConfigurationException {\n        T mojo;","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java#L654-L690","documentation":"The dependency result was computed, but the reflective Field.set on the @Dependencies-annotated field threw IllegalAccessException: the write was denied. setAccessible(true) was already called, so the usual culprits are a final field (modern JDKs refuse reflective writes to final fields) or module/SecurityManager restrictions blocking deep reflection into the plugin's classes.","triggerScenarios":"The annotated field is declared final; the mojo classes are loaded under strong encapsulation (non-opened module path) or a SecurityManager vetoes the reflective write during the build.","commonSituations":"Maven-4 plugin authors marking injected fields final out of habit; restrictive JPMS or SecurityManager setups in the build JVM.","solutions":["Remove the final modifier from the annotated field.","Ensure plugin classes run from the classpath (or a module that opens its packages) so deep reflection is permitted.","Disable any SecurityManager configuration that vetoes reflective writes during the build."],"exampleFix":"// before\n@Dependencies\nprivate final Node node;\n// after\n@Dependencies\nprivate Node node;","handlingStrategy":"validation","validationCode":"for (Field f : MyMojo.class.getDeclaredFields()) {\n    if (f.isAnnotationPresent(Dependencies.class)\n            && (Modifier.isFinal(f.getModifiers()) || Modifier.isStatic(f.getModifiers()))) {\n        throw new IllegalStateException(\"@Dependencies field must be a non-final instance field: \" + f);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    mojo = pluginManager.getConfiguredMojo(mojoInterface, session, mojoExecution);\n} catch (PluginConfigurationException e) {\n    if (e.getCause() instanceof IllegalAccessException) {\n        // reflective write denied: check final/static modifiers and module openness, do not retry\n    }\n    throw e;\n}","preventionTips":["Never mark annotation-injected fields final or static in Maven plugins","Ship a reflection sanity test in every plugin build","Run plugin builds on the classpath (or open the plugin package) so deep reflection is permitted"],"tags":["maven","maven4","reflection","final-field","illegal-access"],"backgroundTag":"reflection-access-denied","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}