abstractdog commented on code in PR #471:
URL: https://github.com/apache/tez/pull/471#discussion_r2999759214
##########
tez-tools/analyzers/job-analyzer/src/main/java/org/apache/tez/analyzer/CSVResult.java:
##########
@@ -93,31 +95,52 @@ public void setComments(String comments) {
'}';
}
- //For testing
- public void dumpToFile(String fileName) throws IOException {
- OutputStreamWriter writer = new OutputStreamWriter(
- new FileOutputStream(new File(fileName)),
- Charset.forName("UTF-8").newEncoder());
- BufferedWriter bw = new BufferedWriter(writer);
- bw.write(Joiner.on(",").join(headers));
- bw.newLine();
- for (String[] record : recordsList) {
-
- if (record.length != headers.length) {
- continue; //LOG error msg?
- }
+ private static File validateOutputFile(String fileName) throws IOException {
+ //null or empty string check
+ if (fileName == null || fileName.trim().isEmpty()) {
+ throw new IllegalArgumentException("fileName must not be null or empty");
+ }
+
+ // resolve relative path
+ File target = new File(fileName).getCanonicalFile();
+ File parent = target.getParentFile();
+
+ // check if the parent directory exists
Review Comment:
the corresponding code is too obvious, we don't need this comment
##########
tez-tools/analyzers/job-analyzer/src/main/java/org/apache/tez/analyzer/CSVResult.java:
##########
@@ -93,31 +95,52 @@ public void setComments(String comments) {
'}';
}
- //For testing
- public void dumpToFile(String fileName) throws IOException {
- OutputStreamWriter writer = new OutputStreamWriter(
- new FileOutputStream(new File(fileName)),
- Charset.forName("UTF-8").newEncoder());
- BufferedWriter bw = new BufferedWriter(writer);
- bw.write(Joiner.on(",").join(headers));
- bw.newLine();
- for (String[] record : recordsList) {
-
- if (record.length != headers.length) {
- continue; //LOG error msg?
- }
+ private static File validateOutputFile(String fileName) throws IOException {
+ //null or empty string check
+ if (fileName == null || fileName.trim().isEmpty()) {
+ throw new IllegalArgumentException("fileName must not be null or empty");
+ }
+
+ // resolve relative path
Review Comment:
the corresponding code is too obvious, we don't need this comment
--
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]