{"record":{"id":"18ef35228a18e8ec","repo":"projectlombok/lombok","slug":"the-to-attribute-is-required","errorCode":null,"errorMessage":"The to attribute is required.","messagePattern":"The to attribute is required\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/delombok/lombok/delombok/ant/DelombokTaskImpl.java","lineNumber":52,"sourceCode":"import org.apache.tools.ant.BuildException;\nimport org.apache.tools.ant.Location;\nimport org.apache.tools.ant.types.Path;\nimport org.apache.tools.ant.types.resources.FileResource;\n\npublic class DelombokTaskImpl {\n\tprivate File fromDir, toDir;\n\tprivate Path classpath;\n\tprivate Path sourcepath;\n\tprivate Path modulepath;\n\tprivate boolean verbose;\n\tprivate String encoding;\n\tprivate Path path;\n\tprivate List<String> formatOptions = new ArrayList<String>();\n\t\n\tpublic void execute(Location location) throws BuildException {\n\t\tif (fromDir == null && path == null) throw new BuildException(\"Either 'from' attribute, or nested <fileset> tags are required.\");\n\t\tif (fromDir != null && path != null) throw new BuildException(\"You can't specify both 'from' attribute and nested filesets. You need one or the other.\");\n\t\tif (toDir == null) throw new BuildException(\"The to attribute is required.\");\n\t\t\n\t\tDelombok delombok = new Delombok();\n\t\tif (verbose) delombok.setVerbose(true);\n\t\ttry {\n\t\t\tif (encoding != null) delombok.setCharset(encoding);\n\t\t} catch (UnsupportedCharsetException e) {\n\t\t\tthrow new BuildException(\"Unknown charset: \" + encoding, location);\n\t\t}\n\t\t\n\t\tif (classpath != null) delombok.setClasspath(classpath.toString());\n\t\tif (sourcepath != null) delombok.setSourcepath(sourcepath.toString());\n\t\tif (modulepath != null) delombok.setModulepath(modulepath.toString());\n\t\t\n\t\ttry {\n\t\t\tdelombok.setFormatPreferences(Delombok.formatOptionsToMap(formatOptions));\n\t\t} catch (InvalidFormatOptionException e) {\n\t\t\tthrow new BuildException(e.getMessage() + \" Run java -jar lombok.jar --format-help for detailed format help.\");\n\t\t}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/projectlombok/lombok/blob/6d6a3e9fec0a9555702561fbeb8eac836575116e/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java#L34-L70","documentation":"DelombokTaskImpl.execute requires an output directory: delombok must write somewhere, so `to` must be set. If `toDir` is null after input validation passes, the task throws BuildException 'The to attribute is required.'","triggerScenarios":"An Ant `<delombok from=\"src\">` (or fileset-based) task without a `to` attribute; calling `execute(Location)` programmatically without `setTo(...)`.","commonSituations":"Newly written Ant targets missing the output attribute; renaming/refactoring that dropped `to`; assuming delombok writes in place (it never does — see the same-location guard).","solutions":["Add `to=\"build/delomboked\"` to the delombok task","Call `setTo(File)` when configuring the task programmatically","Ensure the value is a distinct directory from the input"],"exampleFix":"<!-- before -->\n<delombok from=\"src/main/java\"/>\n<!-- after -->\n<delombok from=\"src/main/java\" to=\"build/delomboked\"/>","handlingStrategy":"validation","validationCode":"if (toDir == null) throw new IllegalStateException(\"delombok 'to' attribute must be set\");","typeGuard":null,"tryCatchPattern":"catch (BuildException e) { if (e.getMessage().equals(\"The to attribute is required.\")) { /* set to */ } throw e; }","preventionTips":["Always set `to` when creating a delombok task","Point `to` at a dedicated build output directory","Add the task to CI so missing attributes fail fast"],"tags":["ant","build","missing-attribute","output"],"backgroundTag":"missing-required-option","analyzedSha":"6d6a3e9fec0a9555702561fbeb8eac836575116e","analyzedAt":"2026-09-07T23:18:01.841Z","contentChangedAt":"2026-09-07T23:18:01.841Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}