Reamer commented on code in PR #5000:
URL: https://github.com/apache/zeppelin/pull/5000#discussion_r2230975558
##########
zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/launcher/SparkInterpreterLauncher.java:
##########
@@ -272,22 +272,34 @@ private String detectSparkScalaVersion(String sparkHome,
Map<String, String> env
builder.environment().putAll(env);
File processOutputFile = File.createTempFile("zeppelin-spark", ".out");
builder.redirectError(processOutputFile);
- Process process = builder.start();
- process.waitFor();
- String processOutput = IOUtils.toString(new
FileInputStream(processOutputFile), StandardCharsets.UTF_8);
- Pattern pattern = Pattern.compile(".*Using Scala version (.*),.*");
- Matcher matcher = pattern.matcher(processOutput);
- if (matcher.find()) {
- String scalaVersion = matcher.group(1);
- if (scalaVersion.startsWith("2.12")) {
- return "2.12";
- } else if (scalaVersion.startsWith("2.13")) {
- return "2.13";
+
+ try {
+ Process process = builder.start();
+ process.waitFor();
+
+ String processOutput;
+ try (FileInputStream in = new FileInputStream(processOutputFile)) {
Review Comment:
Please use `FileUtils.readFileToString(...)` instead.
https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#readFileToString(java.io.File,java.lang.String)
##########
zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/launcher/SparkInterpreterLauncher.java:
##########
@@ -272,22 +272,34 @@ private String detectSparkScalaVersion(String sparkHome,
Map<String, String> env
builder.environment().putAll(env);
File processOutputFile = File.createTempFile("zeppelin-spark", ".out");
Review Comment:
You can use the following function here.
`Files.createTempFile(...)`
https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#createTempFile-java.lang.String-java.lang.String-java.nio.file.attribute.FileAttribute...-
##########
zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/launcher/SparkInterpreterLauncher.java:
##########
@@ -272,22 +272,34 @@ private String detectSparkScalaVersion(String sparkHome,
Map<String, String> env
builder.environment().putAll(env);
File processOutputFile = File.createTempFile("zeppelin-spark", ".out");
builder.redirectError(processOutputFile);
- Process process = builder.start();
- process.waitFor();
- String processOutput = IOUtils.toString(new
FileInputStream(processOutputFile), StandardCharsets.UTF_8);
- Pattern pattern = Pattern.compile(".*Using Scala version (.*),.*");
- Matcher matcher = pattern.matcher(processOutput);
- if (matcher.find()) {
- String scalaVersion = matcher.group(1);
- if (scalaVersion.startsWith("2.12")) {
- return "2.12";
- } else if (scalaVersion.startsWith("2.13")) {
- return "2.13";
+
+ try {
+ Process process = builder.start();
+ process.waitFor();
+
+ String processOutput;
+ try (FileInputStream in = new FileInputStream(processOutputFile)) {
+ processOutput = IOUtils.toString(in, StandardCharsets.UTF_8);
+ }
+
+ Pattern pattern = Pattern.compile(".*Using Scala version (.*),.*");
+ Matcher matcher = pattern.matcher(processOutput);
+ if (matcher.find()) {
+ String scalaVersion = matcher.group(1);
+ if (scalaVersion.startsWith("2.12")) {
+ return "2.12";
+ } else if (scalaVersion.startsWith("2.13")) {
+ return "2.13";
+ } else {
+ throw new Exception("Unsupported scala version: " + scalaVersion);
+ }
} else {
- throw new Exception("Unsupported scala version: " + scalaVersion);
+ return detectSparkScalaVersionByReplClass(sparkHome);
+ }
+ } finally {
+ if (!processOutputFile.delete() && processOutputFile.exists()) {
Review Comment:
Deletion should be done with this function.
`Files.deleteIfExists(...)`
https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#deleteIfExists-java.nio.file.Path-
--
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]