lsp-java icon indicating copy to clipboard operation
lsp-java copied to clipboard

Test runner crashes with long classpaths

Open guseggert opened this issue 5 years ago • 3 comments

Describe the bug When I try to run unit tests using M-x dap-java-run-test-class or M-x dap-java-run-test-method, for certain projects with large classpaths the test runner returns an Argument list too long error:

Debug Adapter started at Sun Nov 22 18:22:52

java -cp $JUNIT_CLASS_PATH org.testng.TestNG -d build/test-output -testclass <redacted> -log 2
emacs27: /bin/bash: Argument list too long

Debug Adapter exited abnormally with code 126 at Sun Nov 22 18:22:52

Here's some more information about the classpath:

ELISP> (let* ((cp (-> (dap-java--run-unit-test-command dap-java-java-command t)
		      (plist-get :environment-variables)
		      (->> (assoc "JUNIT_CLASS_PATH"))
		      (cdr))))
	 (list :length (length cp) :jars (length (s-split ":" cp))))
(:length 137765 :jars 789)

ELISP> (s-trim (shell-command-to-string "ulimit -s"))
"9788"
ELISP> (s-trim (shell-command-to-string "getconf ARG_MAX"))
"2505728"

To Reproduce Add a lot of JARs to a project's classpath, or make dap-java-test-additional-args really long.

Expected behavior Unit tests run successfully.

I believe javac allows passing arguments in a file to avoid encountering these kinds of limits, see https://docs.oracle.com/en/java/javase/11/tools/javac.html#GUID-AEEC9F07-CB49-4E96-8BC7-BCC2C7F725C9

This seems like it's exacerbated by the fact that the classpath is stored both in the JUNIT_CLASS_PATH environment variable and passed as an arg to javac, both of which are counted against the ARG_MAX limit.

guseggert avatar Nov 23 '20 06:11 guseggert

I think that vscode(and maybe the other IDEs) here generates a jar which holds the classpath and then it runs this with java -jar.

I believe javac allows passing arguments in a file to avoid encountering these kinds of limits, see https://docs.oracle.com/en/java/javase/11/tools/javac.html#GUID-AEEC9F07-CB49-4E96-8BC7-BCC2C7F725C9

We need to pass arguments to java not javac.

yyoncho avatar Nov 23 '20 06:11 yyoncho

Ah yes thanks. This would be the right doc link then:

https://docs.oracle.com/en/java/javase/11/tools/java.html#GUID-4856361B-8BFD-4964-AE84-121F5F6CF111

Looks like java in Java 8 doesn't support argfiles, perhaps that's why VS Code uses a pathing jar? Which approach do you think is better?

guseggert avatar Nov 23 '20 06:11 guseggert

We try to support java 8 but I won't reject a PR which allows using argfiles

yyoncho avatar Nov 23 '20 08:11 yyoncho