Ver Fonte

Attach parent exceptions to JPlag exceptions to preserve the root cause.

Alberth há 4 anos atrás
pai
commit
e0a23c57e2

+ 2 - 2
jplag/src/main/java/de/jplag/Submission.java

@@ -97,8 +97,8 @@ public class Submission implements Comparable<Submission> {
     public File getCanonicalRoot() throws ExitException {
         try {
             return submissionRoot.getCanonicalFile();
-        } catch (IOException e) {
-            throw new SubmissionException(String.format("Cannot compute canonical file path of \"%s\".", submissionRoot.toString()));
+        } catch (IOException exception) {
+            throw new SubmissionException(String.format("Cannot compute canonical file path of \"%s\".", submissionRoot.toString()), exception);
         }
     }
 

+ 2 - 2
jplag/src/main/java/de/jplag/SubmissionSet.java

@@ -58,7 +58,7 @@ public class SubmissionSet {
     /**
      * Retrieve the base code of this collection.<br>
      * <b>Asking for a non-existing basecode crashes the errorConsumer.</b>
-     * 
+     *
      * @return The base code submission.
      * @see #hasBaseCode
      */
@@ -107,7 +107,7 @@ public class SubmissionSet {
                 parseBaseCodeSubmission(baseCodeSubmission.get()); // cannot use ifPresent because of throws declaration
             }
         } catch (OutOfMemoryError exception) {
-            throw new SubmissionException("Out of memory during parsing of submission \"" + currentSubmissionName + "\"");
+            throw new SubmissionException("Out of memory during parsing of submission \"" + currentSubmissionName + "\"", exception);
         }
         if (errorCollector.hasErrors()) {
             errorCollector.printCollectedErrors();

+ 3 - 3
jplag/src/main/java/de/jplag/SubmissionSetBuilder.java

@@ -128,8 +128,8 @@ public class SubmissionSetBuilder {
         try {
             return processDirEntry(basecodeSubmission);
 
-        } catch (SubmissionException ex) {
-            throw new BasecodeException(ex.getMessage()); // Change thrown exception to basecode exception.
+        } catch (SubmissionException exception) {
+            throw new BasecodeException(exception.getMessage(), exception); // Change thrown exception to basecode exception.
 
         } catch (ExitException ex) {
             throw ex;
@@ -177,7 +177,7 @@ public class SubmissionSetBuilder {
         try {
             fileNames = rootDirectory.list();
         } catch (SecurityException exception) {
-            throw new RootDirectoryException("Cannot list files of the root directory! " + exception.getMessage());
+            throw new RootDirectoryException("Cannot list files of the root directory! " + exception.getMessage(), exception);
         }
 
         if (fileNames == null) {

+ 4 - 0
jplag/src/main/java/de/jplag/exceptions/BasecodeException.java

@@ -10,4 +10,8 @@ public class BasecodeException extends ExitException {
     public BasecodeException(String message) {
         super(message);
     }
+
+    public BasecodeException(String message, Throwable cause) {
+        super(message, cause);
+    }
 }

+ 3 - 0
jplag/src/main/java/de/jplag/exceptions/RootDirectoryException.java

@@ -11,4 +11,7 @@ public class RootDirectoryException extends ExitException {
         super(message);
     }
 
+    public RootDirectoryException(String message, Throwable cause) {
+        super(message, cause);
+    }
 }

+ 3 - 0
jplag/src/main/java/de/jplag/exceptions/SubmissionException.java

@@ -11,4 +11,7 @@ public class SubmissionException extends ExitException {
         super(message);
     }
 
+    public SubmissionException(String message, Throwable cause) {
+        super(message, cause);
+    }
 }

+ 2 - 2
jplag/src/main/java/de/jplag/reporting/Report.java

@@ -115,8 +115,8 @@ public class Report { // Mostly legacy code with some minor improvements.
 
         try {
             return HTMLFile.fromFile(file);
-        } catch (IOException e) {
-            throw new ReportGenerationException("Error opening file: " + file);
+        } catch (IOException exception) {
+            throw new ReportGenerationException("Error opening file: " + file, exception);
         }
     }