Skip to content

JavacCompiler emits -processor with an empty argument for a zero-length annotationProcessors array #512

Description

@slachiewicz

JavacCompiler decides whether to pass -processor by a null check alone, so a zero-length annotationProcessors array produces -processor followed by an empty argument. javac then fails because the empty processor name cannot be resolved.

JavacCompiler.java, in buildCompilerArguments:

if (config.getAnnotationProcessors() != null) {
    args.add("-processor");
    String[] procs = config.getAnnotationProcessors();
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < procs.length; i++) {
        if (i > 0) {
            buffer.append(",");
        }
        buffer.append(procs[i]);
    }
    args.add(buffer.toString());
}

With procs.length == 0 the buffer stays empty and the emitted arguments are -processor and "".

EclipseJavaCompiler guards the same field differently and is unaffected:

if (annotationProcessors != null && annotationProcessors.length > 0) {

That difference is why the failure only reproduces under javac.

How it surfaces

Maven maps an explicitly empty <annotationProcessors/> block to an array holding one blank string rather than to an empty array or null, so maven-compiler-plugin hands the array straight through and the build fails. That is MCOMPILER-607, and apache/maven-compiler-plugin#1077 works around it by normalizing the array to null before it reaches Plexus Compiler.

The workaround is correct and worth merging on its own, but it lives in one caller. Any other caller that builds a CompilerConfiguration with an empty processor array reaches the same -processor "".

Suggested change

Match EclipseJavaCompiler by adding the length check. Two compilers currently disagree about the meaning of the same field, and aligning them removes the class of bug rather than one instance of it.

This issue was created with AI assistance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions