This is an automated email from the ASF dual-hosted git repository.

amoeba pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-cookbook.git


The following commit(s) were added to refs/heads/main by this push:
     new 6b0ef33  MINOR: [CI][Java] Work around Maven stdout/stderr issue (#415)
6b0ef33 is described below

commit 6b0ef33e874dd370efb87a8b2bfb096ef69b3af4
Author: Bryce Mecum <[email protected]>
AuthorDate: Thu Oct 15 16:12:49 2026 -0700

    MINOR: [CI][Java] Work around Maven stdout/stderr issue (#415)
    
    Nightly Java Cookbook CI started failing in
    
https://github.com/apache/arrow-cookbook/actions/runs/38504124957/job/115657570017
    with extraneous log output,
    
    ```
    Expected:
        column-1    column-2    column-3
        IRAQ    false    42
        JAPAN    false    43
        JORDAN    true    44
        KENYA    true    45
    Got:
        SLF4J(W): No SLF4J providers were found.
        SLF4J(W): Defaulting to no-operation (NOP) logger implementation
        SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further 
details.
        SLF4J(W): Class path contains SLF4J bindings targeting slf4j-api 
versions 1.7.x or earlier.
        SLF4J(W): Ignoring binding found at 
[jar:file:/home/runner/.m2/repository/org/slf4j/slf4j-jdk14/1.7.30/slf4j-jdk14-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
        SLF4J(W): See https://www.slf4j.org/codes.html#ignoredBindings for an 
explanation.
        column-1    column-2    column-3
        IRAQ    false    42
        JAPAN    false    43
        JORDAN    true    44
        KENYA    true    45
    ```
    
    It looks like a bug got shipped with Maven 3.10 that caused stderr to
    start showing up in stdout which caused test failures. See
    https://www.github.com/apache/maven/issues/13380.
    
    This PR tries an agent-suggested approach which runs the doc example
    directly with java so stdout is clean.
---
 java/ext/javadoctest.py | 38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/java/ext/javadoctest.py b/java/ext/javadoctest.py
index ce59b77..fc4fa9f 100644
--- a/java/ext/javadoctest.py
+++ b/java/ext/javadoctest.py
@@ -43,7 +43,7 @@ class JavaDocTestBuilder(DocTestBuilder):
     Runs java test snippets in the documentation.
 
     The code in each testcode block is insert into a template Maven project,
-    run through exec:java, its output captured and post-processed, and finally
+    compiled with Maven and run with java, its stdout captured and 
post-processed, and finally
     compared to whatever's in the corresponding testoutput.
     """
 
@@ -83,23 +83,49 @@ class JavaDocTestBuilder(DocTestBuilder):
             modified_env = os.environ.copy()
             modified_env["_JAVA_OPTIONS"] = 
"--add-opens=java.base/java.nio=ALL-UNNAMED"
 
-            test_proc = subprocess.Popen(
+            # Run Example.java by compiling it with Maven and then running it
+            # directly with java. We previously used mvn exec:java but a bug in
+            # Mavens' JLine dependency caused us to get stderr on our stdout
+            # which makes tests fail. In theory this could be reverted back to
+            # use exec:java once Maven picks up a fixed JLine depdendency.
+            classpath_file = pathlib.Path(project_dir) / "classpath.txt"
+            build_proc = subprocess.run(
                 [
                     "mvn",
                     "--batch-mode",
+                    "--quiet",
                     "-f",
                     project_dir,
                     "compile",
-                    "exec:java",
-                    "-Dexec.mainClass=org.example.Example",
+                    "dependency:build-classpath",
+                    f"-Dmdep.outputFile={classpath_file}",
                 ],
-                stdin=subprocess.PIPE,
+                stdin=subprocess.DEVNULL,
                 stdout=subprocess.PIPE,
                 text=True,
                 env=modified_env,
             )
 
-            out_java_arrow, err_java_arrow = test_proc.communicate()
+            if build_proc.returncode != 0:
+                # Let the build errors show up as the test's output
+                out_java_arrow = build_proc.stdout
+            else:
+                classpath = os.pathsep.join(
+                    [
+                        str(pathlib.Path(project_dir) / "target" / "classes"),
+                        classpath_file.read_text().strip(),
+                    ]
+                )
+
+                test_proc = subprocess.Popen(
+                    ["java", "-cp", classpath, "org.example.Example"],
+                    stdin=subprocess.PIPE,
+                    stdout=subprocess.PIPE,
+                    text=True,
+                    env=modified_env,
+                )
+
+                out_java_arrow, err_java_arrow = test_proc.communicate()
 
         # continue with python logic code to do java output validation
         output = f"print('''{self.clean_output(out_java_arrow)}''')"

Reply via email to