You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemds.apache.org by ba...@apache.org on 2022/01/21 12:27:40 UTC
[systemds] branch main updated: [MINOR] Fix deprecated calls/warnings from Java 11
This is an automated email from the ASF dual-hosted git repository.
baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/main by this push:
new 1b0fd02 [MINOR] Fix deprecated calls/warnings from Java 11
1b0fd02 is described below
commit 1b0fd022c7c2874edba13d1f4e2539eecac5fc8d
Author: baunsgaard <ba...@tugraz.at>
AuthorDate: Thu Jan 20 20:32:40 2022 +0100
[MINOR] Fix deprecated calls/warnings from Java 11
Closes #1516
---
.../sysds/api/mlcontext/MLContextConversionUtil.java | 3 ++-
.../org/apache/sysds/api/mlcontext/ScriptFactory.java | 11 ++++++-----
src/main/java/org/apache/sysds/parser/ParserWrapper.java | 3 ++-
.../org/apache/sysds/parser/dml/DMLParserWrapper.java | 15 ++++++---------
src/main/java/org/apache/sysds/runtime/io/ReaderHDF5.java | 1 -
.../java/org/apache/sysds/runtime/io/ReaderTextCSV.java | 1 -
.../org/apache/sysds/runtime/io/ReaderTextLIBSVM.java | 1 -
.../java/org/apache/sysds/runtime/io/WriterTextCSV.java | 1 -
.../apache/sysds/runtime/iogen/MatrixGenerateReader.java | 1 -
.../java/org/apache/sysds/test/AutomatedTestBase.java | 7 ++++---
.../federated/multitenant/FederatedMultiTenantTest.java | 10 +++++-----
11 files changed, 25 insertions(+), 29 deletions(-)
diff --git a/src/main/java/org/apache/sysds/api/mlcontext/MLContextConversionUtil.java b/src/main/java/org/apache/sysds/api/mlcontext/MLContextConversionUtil.java
index 0afa2d1..b889cb1 100644
--- a/src/main/java/org/apache/sysds/api/mlcontext/MLContextConversionUtil.java
+++ b/src/main/java/org/apache/sysds/api/mlcontext/MLContextConversionUtil.java
@@ -21,6 +21,7 @@ package org.apache.sysds.api.mlcontext;
import java.io.InputStream;
import java.net.URL;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -130,7 +131,7 @@ public class MLContextConversionUtil {
*/
public static MatrixObject urlToMatrixObject(URL url, MatrixMetadata matrixMetadata) {
try (InputStream is = url.openStream()) {
- List<String> lines = IOUtils.readLines(is);
+ List<String> lines = IOUtils.readLines(is, Charset.defaultCharset());
JavaRDD<String> javaRDD = jsc().parallelize(lines);
if ((matrixMetadata == null) || (matrixMetadata.getMatrixFormat() == MatrixFormat.CSV))
return javaRDDStringCSVToMatrixObject(javaRDD, matrixMetadata);
diff --git a/src/main/java/org/apache/sysds/api/mlcontext/ScriptFactory.java b/src/main/java/org/apache/sysds/api/mlcontext/ScriptFactory.java
index 84c3313..d1a8e93 100644
--- a/src/main/java/org/apache/sysds/api/mlcontext/ScriptFactory.java
+++ b/src/main/java/org/apache/sysds/api/mlcontext/ScriptFactory.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.nio.charset.Charset;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
@@ -246,7 +247,7 @@ public class ScriptFactory {
}
String filePath = file.getPath();
try {
- return FileUtils.readFileToString(file);
+ return FileUtils.readFileToString(file, Charset.defaultCharset());
} catch (IOException e) {
throw new MLContextException("Error trying to read script string from file: " + filePath, e);
}
@@ -272,12 +273,12 @@ public class ScriptFactory {
Path path = new Path(scriptFilePath);
FileSystem fs = IOUtilFunctions.getFileSystem(path);
try( FSDataInputStream fsdis = fs.open(path) ) {
- return IOUtils.toString(fsdis);
+ return IOUtils.toString(fsdis, Charset.defaultCharset());
}
}
// from local file system
File scriptFile = new File(scriptFilePath);
- return FileUtils.readFileToString(scriptFile);
+ return FileUtils.readFileToString(scriptFile, Charset.defaultCharset());
}
catch (IllegalArgumentException | IOException e) {
throw new MLContextException("Error trying to read script string from file: " + scriptFilePath, e);
@@ -298,7 +299,7 @@ public class ScriptFactory {
throw new MLContextException("InputStream is null");
}
try {
- return IOUtils.toString(inputStream);
+ return IOUtils.toString(inputStream, Charset.defaultCharset());
} catch (IOException e) {
throw new MLContextException("Error trying to read script string from InputStream", e);
}
@@ -343,7 +344,7 @@ public class ScriptFactory {
throw new MLContextException("Currently only reading from http and https URLs is supported");
}
try( InputStream is = url.openStream() ) {
- return IOUtils.toString(is);
+ return IOUtils.toString(is, Charset.defaultCharset());
} catch (IOException e) {
throw new MLContextException("Error trying to read script string from URL: " + url, e);
}
diff --git a/src/main/java/org/apache/sysds/parser/ParserWrapper.java b/src/main/java/org/apache/sysds/parser/ParserWrapper.java
index e0a3942..118bf8e 100644
--- a/src/main/java/org/apache/sysds/parser/ParserWrapper.java
+++ b/src/main/java/org/apache/sysds/parser/ParserWrapper.java
@@ -24,6 +24,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
@@ -142,7 +143,7 @@ public abstract class ParserWrapper {
}
}
}
- return IOUtils.toString(is);
+ return IOUtils.toString(is, Charset.defaultCharset());
}
finally {
IOUtilFunctions.closeSilently(is);
diff --git a/src/main/java/org/apache/sysds/parser/dml/DMLParserWrapper.java b/src/main/java/org/apache/sysds/parser/dml/DMLParserWrapper.java
index 57c1b62..03be2af 100644
--- a/src/main/java/org/apache/sysds/parser/dml/DMLParserWrapper.java
+++ b/src/main/java/org/apache/sysds/parser/dml/DMLParserWrapper.java
@@ -22,12 +22,12 @@ package org.apache.sysds.parser.dml;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Map;
import java.util.Map.Entry;
-import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.BailErrorStrategy;
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.DefaultErrorStrategy;
import org.antlr.v4.runtime.atn.PredictionMode;
@@ -100,14 +100,11 @@ public class DMLParserWrapper extends ParserWrapper
public DMLProgram doParse(String fileName, String dmlScript, String sourceNamespace, Map<String,String> argVals) {
DMLProgram dmlPgm = null;
- ANTLRInputStream in;
+ CharStream in;
try {
- if(dmlScript == null) {
+ if(dmlScript == null)
dmlScript = readDMLScript(fileName, LOG);
- }
-
- InputStream stream = new ByteArrayInputStream(dmlScript.getBytes());
- in = new ANTLRInputStream(stream);
+ in = CharStreams.fromStream(new ByteArrayInputStream(dmlScript.getBytes()));
} catch (FileNotFoundException e) {
throw new ParseException("Cannot find file/resource: " + fileName, e);
} catch (IOException e) {
@@ -137,7 +134,7 @@ public class DMLParserWrapper extends ParserWrapper
}
catch(ParseCancellationException ex) {
// Error occurred, so now try full LL(*) for better error messages
- tokens.reset();
+ tokens.seek(0);
antlr4Parser.reset();
if(fileName != null) {
errorListener.setCurrentFileName(fileName);
diff --git a/src/main/java/org/apache/sysds/runtime/io/ReaderHDF5.java b/src/main/java/org/apache/sysds/runtime/io/ReaderHDF5.java
index 19295a4..2dc6bb1 100644
--- a/src/main/java/org/apache/sysds/runtime/io/ReaderHDF5.java
+++ b/src/main/java/org/apache/sysds/runtime/io/ReaderHDF5.java
@@ -90,7 +90,6 @@ public class ReaderHDF5 extends MatrixReader {
return ret;
}
- @SuppressWarnings("unchecked")
private static MatrixBlock readHDF5MatrixFromHDFS(Path path, JobConf job,
FileSystem fs, MatrixBlock dest, long rlen, long clen, int blen, String datasetName)
throws IOException, DMLRuntimeException {
diff --git a/src/main/java/org/apache/sysds/runtime/io/ReaderTextCSV.java b/src/main/java/org/apache/sysds/runtime/io/ReaderTextCSV.java
index 39f909b..ae6027a 100644
--- a/src/main/java/org/apache/sysds/runtime/io/ReaderTextCSV.java
+++ b/src/main/java/org/apache/sysds/runtime/io/ReaderTextCSV.java
@@ -94,7 +94,6 @@ public class ReaderTextCSV extends MatrixReader
return ret;
}
- @SuppressWarnings("unchecked")
private static MatrixBlock readCSVMatrixFromHDFS( Path path, JobConf job, FileSystem fs, MatrixBlock dest,
long rlen, long clen, int blen, boolean hasHeader, String delim, boolean fill, double fillValue, HashSet<String> naStrings )
throws IOException, DMLRuntimeException
diff --git a/src/main/java/org/apache/sysds/runtime/io/ReaderTextLIBSVM.java b/src/main/java/org/apache/sysds/runtime/io/ReaderTextLIBSVM.java
index 4a94d22..15162d1 100644
--- a/src/main/java/org/apache/sysds/runtime/io/ReaderTextLIBSVM.java
+++ b/src/main/java/org/apache/sysds/runtime/io/ReaderTextLIBSVM.java
@@ -89,7 +89,6 @@ public class ReaderTextLIBSVM extends MatrixReader {
return ret;
}
- @SuppressWarnings("unchecked")
private static MatrixBlock readLIBSVMMatrixFromHDFS( Path path, JobConf job, FileSystem fs, MatrixBlock dest,
long rlen, long clen, int blen) throws IOException, DMLRuntimeException
{
diff --git a/src/main/java/org/apache/sysds/runtime/io/WriterTextCSV.java b/src/main/java/org/apache/sysds/runtime/io/WriterTextCSV.java
index 5a9c686..b81320e 100644
--- a/src/main/java/org/apache/sysds/runtime/io/WriterTextCSV.java
+++ b/src/main/java/org/apache/sysds/runtime/io/WriterTextCSV.java
@@ -236,7 +236,6 @@ public class WriterTextCSV extends MatrixWriter
}
}
- @SuppressWarnings({ "unchecked" })
public final void addHeaderToCSV(String srcFileName, String destFileName, long rlen, long clen)
throws IOException
{
diff --git a/src/main/java/org/apache/sysds/runtime/iogen/MatrixGenerateReader.java b/src/main/java/org/apache/sysds/runtime/iogen/MatrixGenerateReader.java
index e628ca1..c377dbc 100644
--- a/src/main/java/org/apache/sysds/runtime/iogen/MatrixGenerateReader.java
+++ b/src/main/java/org/apache/sysds/runtime/iogen/MatrixGenerateReader.java
@@ -115,7 +115,6 @@ public abstract class MatrixGenerateReader extends MatrixReader {
return ret;
}
- @SuppressWarnings("unchecked")
private MatrixBlock readMatrixFromHDFS(Path path, JobConf job, FileSystem fs, MatrixBlock dest, long rlen,
long clen, int blen) throws IOException, DMLRuntimeException {
//prepare file paths in alphanumeric order
diff --git a/src/test/java/org/apache/sysds/test/AutomatedTestBase.java b/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
index cb53abc..af00ec3 100644
--- a/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
+++ b/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
@@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -1198,7 +1199,7 @@ public abstract class AutomatedTestBase {
// if R < 4.0 on Windows is used, the file separator needs to be Windows style
if(System.getProperty("os.name").contains("Windows")) {
Process r_ver_cmd = Runtime.getRuntime().exec("RScript --version");
- String r_ver = IOUtils.toString(r_ver_cmd.getErrorStream());
+ String r_ver = IOUtils.toString(r_ver_cmd.getErrorStream(), Charset.defaultCharset());
if(!r_ver.contains("4.0")) {
cmd = cmd.replace('/', '\\');
executionFile = executionFile.replace('/', '\\');
@@ -1212,8 +1213,8 @@ public abstract class AutomatedTestBase {
}
Process child = Runtime.getRuntime().exec(cmd);
- outputR = IOUtils.toString(child.getInputStream());
- errorString = IOUtils.toString(child.getErrorStream());
+ outputR = IOUtils.toString(child.getInputStream(), Charset.defaultCharset());
+ errorString = IOUtils.toString(child.getErrorStream(), Charset.defaultCharset());
//
// To give any stream enough time to print all data, otherwise there
diff --git a/src/test/java/org/apache/sysds/test/functions/federated/multitenant/FederatedMultiTenantTest.java b/src/test/java/org/apache/sysds/test/functions/federated/multitenant/FederatedMultiTenantTest.java
index 1b545ff..8852931 100644
--- a/src/test/java/org/apache/sysds/test/functions/federated/multitenant/FederatedMultiTenantTest.java
+++ b/src/test/java/org/apache/sysds/test/functions/federated/multitenant/FederatedMultiTenantTest.java
@@ -19,15 +19,15 @@
package org.apache.sysds.test.functions.federated.multitenant;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
-import java.lang.Math;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
-import static org.junit.Assert.fail;
-
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.sysds.api.DMLScript;
@@ -361,8 +361,8 @@ public class FederatedMultiTenantTest extends AutomatedTestBase {
//wait for process, but obtain logs before to avoid blocking
String outputLog = null, errorLog = null;
try {
- outputLog = IOUtils.toString(coord.getInputStream());
- errorLog = IOUtils.toString(coord.getErrorStream());
+ outputLog = IOUtils.toString(coord.getInputStream(), Charset.defaultCharset());
+ errorLog = IOUtils.toString(coord.getErrorStream(), Charset.defaultCharset());
coord.waitFor();
}