Просмотр исходного кода

Fix bug for absolute paths from parser tokens. (#85)

* Fix bug for absolute paths from parser tokens.

Co-authored-by: Albert Hofkamp <a.t.hofkamp@tue.nl>
Co-authored-by: Timur Sağlam <timur.saglam@kit.edu>
Alberth289346 5 лет назад
Родитель
Сommit
3445d22660
1 измененных файлов с 11 добавлено и 6 удалено
  1. 11 6
      jplag/src/main/java/jplag/Submission.java

+ 11 - 6
jplag/src/main/java/jplag/Submission.java

@@ -201,24 +201,29 @@ public class Submission implements Comparable<Submission> {
         char[][] result = new char[files.length][];
 
         for (int i = 0; i < files.length; i++) {
+            // If the token path is absolute, ignore the provided directory
+            File file = new File(files[i]);
+            if (!file.isAbsolute()) {
+                file = new File(submissionFile, files[i]);
+            }
+            
             try {
-                File file = new File(submissionFile, files[i]);
                 int size = (int) file.length();
                 char[] buffer = new char[size];
 
-                FileReader fis = new FileReader(file);
+                FileReader reader = new FileReader(file);
 
-                if (size != fis.read(buffer)) {
+                if (size != reader.read(buffer)) {
                     System.out.println("Not right size read from the file, " + "but I will still continue...");
                 }
 
                 result[i] = buffer;
-                fis.close();
+                reader.close();
             } catch (FileNotFoundException e) {
                 // TODO PB: Should an ExitException be thrown here?
-                System.out.println("File not found: " + ((new File(submissionFile, files[i])).toString()));
+                System.out.println("File not found: " + file.getPath());
             } catch (IOException e) {
-                throw new jplag.ExitException("I/O exception reading file \"" + (new File(submissionFile, files[i])).toString() + "\"!", e);
+                throw new jplag.ExitException("I/O exception reading file \"" + file.getPath() + "\"!", e);
             }
         }