anmolanmol1234 commented on code in PR #8611:
URL: https://github.com/apache/hadoop/pull/8611#discussion_r3665490740


##########
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAggregateMetricsManager.java:
##########
@@ -667,6 +667,31 @@ private void runProgramAndCaptureOutput(String program,
     }
   }
 
+  /**
+   * Resolves a JDK tool (e.g. {@code javac}, {@code java}) from the JDK that 
is
+   * currently running this test, rather than relying on whichever version is
+   * first on the {@code PATH}. The spawned {@code javac} must read the 
compiled
+   * classes of this project (and its dependencies) off the classpath; those 
are
+   * emitted by the same JDK that runs the tests. If a mismatched compiler is
+   * picked from the {@code PATH} (e.g. a Java 8 {@code javac} against Java 17
+   * bytecode), compilation fails with "class file has wrong version". 
Anchoring
+   * on {@code java.home} keeps the toolchain consistent. Falls back to the 
bare
+   * tool name when the JDK layout cannot be resolved.
+   *
+   * @param name the tool name, e.g. {@code javac} or {@code java}.
+   * @return an absolute path to the tool inside the running JDK, or {@code 
name}.
+   */
+  private static String jdkTool(String name) {
+    String javaHome = System.getProperty("java.home");

Review Comment:
   Use constants



##########
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAggregateMetricsManager.java:
##########
@@ -667,6 +667,31 @@ private void runProgramAndCaptureOutput(String program,
     }
   }
 
+  /**
+   * Resolves a JDK tool (e.g. {@code javac}, {@code java}) from the JDK that 
is
+   * currently running this test, rather than relying on whichever version is
+   * first on the {@code PATH}. The spawned {@code javac} must read the 
compiled
+   * classes of this project (and its dependencies) off the classpath; those 
are
+   * emitted by the same JDK that runs the tests. If a mismatched compiler is
+   * picked from the {@code PATH} (e.g. a Java 8 {@code javac} against Java 17
+   * bytecode), compilation fails with "class file has wrong version". 
Anchoring
+   * on {@code java.home} keeps the toolchain consistent. Falls back to the 
bare
+   * tool name when the JDK layout cannot be resolved.
+   *
+   * @param name the tool name, e.g. {@code javac} or {@code java}.
+   * @return an absolute path to the tool inside the running JDK, or {@code 
name}.
+   */
+  private static String jdkTool(String name) {
+    String javaHome = System.getProperty("java.home");
+    if (javaHome != null && !javaHome.isEmpty()) {
+      File tool = new File(new File(javaHome, "bin"), name);

Review Comment:
   here as well



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to