https://bz.apache.org/bugzilla/show_bug.cgi?id=69586
Bug ID: 69586 Summary: Javac argument file generation creates invalid classpath entry when compiling Java modules and no classpath is defined. Product: Ant Version: unspecified Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P2 Component: Core Assignee: notifications@ant.apache.org Reporter: slacker6...@gmail.com Target Milestone: --- Created attachment 39996 --> https://bz.apache.org/bugzilla/attachment.cgi?id=39996&action=edit Patch for class org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter Hello, When using the javac task to compile Java modules with a large number of source files, Ant creates a temporary file containing javac arguments. In this file, if no classpath is defined, a "-classpath" option is generated followed by a blank line, causing the next argument (-g) to be incorrectly interpreted as the classpath value. Step to reproduce : # cd /tmp # mkdir -p mymodule/{build,lib,src/mymodule/com/foo/bar} # echo "module mymodule { }" > mymodule/src/mymodule/module-info.java # for i in {1..100} ; do echo -e "package com.foo.bar;\npublic class Class${i} {\n}" > mymodule/src/mymodule/com/foo/bar/Class${i}.java ; done # echo -e "<project basedir=\".\">\n <target name=\"compile\">\n <javac\n includeAntRuntime=\"off\"\n fork=\"on\"\n includeDestClasses=\"off\"\n modulepath=\"lib\"\n modulesourcepath=\"{src/*}\"\n destdir=\"build\"\n debug=\"off\">\n <compilerarg line=\"-Xlint:path\"/>\n </javac>\n </target>\n</project>" > mymodule/build.xml # cd /tmp/mymodule # ant -d compile Apache Ant(TM) version 1.10.15 compiled on November 4 2024 Trying the default build file: build.xml ... Setting project property: ant.auto.tmpdir -> /tmp/ant12471706666314375667 Execute:Java13CommandLauncher: Executing '/usr/lib64/jvm/java-21-openjdk-21/bin/javac' with arguments: '--module-source-path' '/tmp/TEST/CHECK/mymodule/{src/*}' '@/tmp/ant12471706666314375667/files15467176437172822301' The ' characters around the executable and arguments are not part of the command. [javac] warning: [path] bad path element "-g": no such file or directory [javac] warning: [path] bad path element "none": no such file or directory [javac] 2 warnings BUILD SUCCESSFUL Total time: 0 seconds In the example above, the javac's argument file contains the following : -d /tmp/mymodule/build -classpath -g:none -Xlint:path --module-source-path /tmp/mymodule/{src/*} --module-path /tmp/mymodule/lib In this situation, the .class files contain the default debug informations (i.e. the line number and source file) instead of containing no debug information at all. The following patch fixes this issue (also in attachment) : --- DefaultCompilerAdapter.java.orig 2025-02-17 11:55:45.167967569 +0100 +++ DefaultCompilerAdapter.java 2025-02-17 17:02:02.373473718 +0100 @@ -304,8 +304,6 @@ cmd.createArgument().setFile(destDir); } - cmd.createArgument().setValue("-classpath"); - // Just add "sourcepath" to classpath (for JDK1.1) // as well as "bootclasspath" and "extdirs" if (!assumeJava1_2Plus()) { @@ -317,9 +315,15 @@ } cp.append(classpath); cp.append(sourcepath); + + cmd.createArgument().setValue("-classpath"); cmd.createArgument().setPath(cp); } else { - cmd.createArgument().setPath(classpath); + if (!classpath.toString().isEmpty()) { + cmd.createArgument().setValue("-classpath"); + cmd.createArgument().setPath(classpath); + } + // If the buildfile specifies sourcepath="", then don't // output any sourcepath. if (sourcepath.size() > 0) { Hope this helps. -- SeB -- You are receiving this mail because: You are the assignee for the bug.