reuvenlax commented on PR #41083: URL: https://github.com/apache/beam/pull/41083#issuecomment-7291353299
I'm not an expert on classpath resolution, so this review is agent assisted: Verdict: Stop — Both the Root-Cause Diagnosis and Proposed Solution Have Fundamental Flaws I fetched PR [#41083](https://github.com/apache/beam/pull/41083) and issue [#41079](https://github.com/apache/beam/issues/41079), verified the claim against OpenJDK javac (FSInfo) and Beam's container/Prism code, and empirically reproduced the failure on JDK 21. Because the problem description misdiagnoses the JDK 11+ failure and the proposed fix still fails on the exact PrismRunner reproducer in #41079, I skipped launching the performance/correctness/readability subagents. 1. Problem Description Analysis What is real (and answers @kennknowles's question on the PR) Kenn asked: "Wouldn't it cause most/all pipelines to fail if it could not resolve Row?" Why normal pipelines don't fail: Only JavaRowUdf.java (used exclusively by Beam YAML's JavaFilterTransformProvider.java and JavaMapToFieldsTransformProvider.java) invokes javac at runtime via StringCompiler.java. Because JavaRowUdf.function is transient, it compiles fine during expansion (outside FnHarness), then recompiles lazily on the first element inside FnHarness (JavaRowUdf.java). Normal Beam pipelines only use the JVM runtime classloader (URLClassPath), which loads Row fine. Additionally, the existing if (cl instanceof URLClassLoader) block in StringCompiler.java was genuinely broken for non-system URLClassLoader environments (e.g., Flink/Spark/custom classloaders): it never added url itself to cp, added null when a JAR had no Class-Path header, and didn't split space-separated manifest entries. What is wrong in PR #41083's diagnosis PR #41083 claims the FnHarness failure happens because on JDK 11+ AppClassLoader is not a URLClassLoader, causing StringCompiler to skip parsing pathing.jar's Class-Path: file:/... manifest. This is inaccurate for modern JDKs (JDK 11.0.8+, 17, 21 — all supported Beam containers): OpenJDK's javac (com.sun.tools.javac.file.Locations$ClassPathLocationHandler → FSInfo.getJarClassPath) already expands Class-Path: file:/... inside pathing.jar (fixed in JDK-8218268; verified directly in openjdk/jdk11u and openjdk/jdk17u FSInfo.java and tested live on JDK 21 with a pathing.jar generated identically to pathingjar.go). Passing -classpath pathing.jar to javac succeeds on normal paths. The actual root cause on PrismRunner (#41079's reproducer): Java expansion service registers the Java Docker environment ID via uniqify(env.getUrn(), ...) → external_1beam:env:docker:v1 (contains colons :) (ExpansionService.java, SdkComponents.java, beam_runner_api.proto). PrismRunner builds workerId as fmt.Sprintf("%v[%v]", j.key, j.jobName) + "_" + env → job-001[BeamApp-...]_external_1beam:env:docker:v1 (contains both [ ] and :) (job.go, worker.go, environments.go). boot.go materializes staged JARs (including beam-sdks-java-core / expansion shadow JAR containing Row) into /tmp/job-001[BeamApp-...]_external_1beam:env:docker:v1/staged/ and calls makePathingJar(cp) (boot.go). pathingjar.go writes unencoded paths ("Class-Path: file:" + strings.Join(classpaths, " file:")) into pathing.jar's manifest. At runtime, the JVM's URLClassPath uses java.net.URL, which tolerates unencoded [ and ]. javac's FSInfo.getJarClassPath calls url.toURI(), which throws URISyntaxException: Illegal character in path on [ and ], causing javac to abort loading the entire pathing.jar manifest and fail with package org.apache.beam.sdk.values does not exist. 2. Why the Proposed Solution Fails Fatal bug — PR #41083 still fails on #41079's PrismRunner reproducer: PR #41083 extracts the staged JAR path /tmp/job-001[BeamApp-...]_external_1beam:env:docker:v1/staged/beam-sdks-java-core.jar (both from pathing.jar and from Row.class's CodeSource), and then joins the list with File.pathSeparator (: on Linux) and passes it to javac as -classpath <string>. javac splits -classpath on :, shattering the path into 4 nonexistent segments (/tmp/job-001[...]_external_1beam, env, docker, v1/staged/...jar). Verified empirically on JDK 21: both the original code and PR #41083 fail with the exact same package org.apache.beam.sdk.values does not exist / cannot find symbol: class Row error, whereas passing List<File> directly via StandardJavaFileManager.setLocation(StandardLocation.CLASS_PATH, files) succeeds cleanly (ok=true). Still passes the broken pathing.jar to javac: Keeping pathing.jar itself in the classpath causes javac to re-run FSInfo.getJarClassPath on it and emit error: error reading .../pathing.jar; java.net.URISyntaxException (which leaks to stderr or diagnostics if a listener is attached). Unnecessary reinvention & incomplete classloader coverage: Adds ~230 lines of custom manifest/URI/Windows path parsing in StringCompiler.java, even though sdks/java/core already shades io.github.classgraph:classgraph (used in ClasspathScanningResourcesDetector.java). Only inspects cl instanceof URLClassLoader without walking parent classloaders, and hardcodes only Row.class and StringCompiler.class (won't help a Java UDF importing types from other staged JARs under a custom classloader). PR hygiene / state notes: PR #41083 currently has an APPROVED review from @kennknowles despite his open question. The author commented on Nov 16 claiming a fix for Gemini's Windows addResourceLocation review comment ([BEAM-41079] Normalize file URL in addResourceLocation for Windows), but that commit was never pushed (HEAD is still 19799cf9 from Nov 9). The PR title is duplicated ([BEAM-41079] Fix StringCompiler classpath resolution[BEAM-41079] Fix StringCompiler classpath resolution). 3. Recommended Direction In StringCompiler.java: Stop passing -classpath <String.join(File.pathSeparator, ...)> to javac; instead pass Iterable<? extends File> directly via StandardJavaFileManager.setLocation(StandardLocation.CLASS_PATH, classpathFiles) so paths containing : (Linux) or ; (Windows) are never corrupted. Exclude expanded pathing JARs (or fix pathingjar.go) so javac doesn't emit error reading pathing.jar; URISyntaxException. Also consider reusing ClassGraph (already a dependency of sdks/java/core) or keeping custom classpath/manifest resolution minimal and walking the ClassLoader parent chain. Upstream fixes worth doing alongside or separately: Percent-encode file: URIs in pathingjar.go per the JAR manifest spec (RFC 3986). Sanitize [ ] and : in Prism's worker ID / staging directory path (boot.go or worker.go), since : is also illegal in Windows paths and breaks any tool using File.pathSeparator -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
