Exception should use FileAccess to get file length JEP-349-branch
authoregahlin
Mon, 28 Oct 2019 17:33:38 +0100
branchJEP-349-branch
changeset 58820 8412a437a4bc
parent 58806 a7d850b47b19
child 58824 13921e9e3cac
Exception should use FileAccess to get file length
src/jdk.jfr/share/classes/jdk/jfr/internal/SecuritySupport.java
src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RecordingInput.java
test/jdk/jdk/jfr/api/consumer/security/TestStreamingLocal.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/SecuritySupport.java	Sat Oct 26 23:59:51 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/SecuritySupport.java	Mon Oct 28 17:33:38 2019 +0100
@@ -474,16 +474,16 @@
 
         @Override
         public  String getAbsolutePath(File f) throws IOException {
-            return doPrivilegedIOWithReturn( () ->f.getAbsolutePath());
+            return doPrivilegedIOWithReturn( () -> f.getAbsolutePath());
         }
         @Override
         public long length(File f) throws IOException {
-            return doPrivilegedIOWithReturn( () ->f.length());
+            return doPrivilegedIOWithReturn( () -> f.length());
         }
 
         @Override
         public  long fileSize(Path p) throws IOException {
-            return doPrivilegedIOWithReturn( () ->Files.size(p));
+            return doPrivilegedIOWithReturn( () -> Files.size(p));
         }
     }
 
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RecordingInput.java	Sat Oct 26 23:59:51 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RecordingInput.java	Mon Oct 28 17:33:38 2019 +0100
@@ -88,7 +88,7 @@
         this.currentBlock.reset();
         previousBlock.reset();
         if (fileAccess.length(f) < 8) {
-            throw new IOException("Not a valid Flight Recorder file. File length is only " + f.length() + " bytes.");
+            throw new IOException("Not a valid Flight Recorder file. File length is only " + fileAccess.length(f) + " bytes.");
         }
     }
 
--- a/test/jdk/jdk/jfr/api/consumer/security/TestStreamingLocal.java	Sat Oct 26 23:59:51 2019 +0200
+++ b/test/jdk/jdk/jfr/api/consumer/security/TestStreamingLocal.java	Mon Oct 28 17:33:38 2019 +0100
@@ -51,6 +51,10 @@
             // Enable JVM event, no write permission needed
             r.enable(EventNames.JVMInformation);
             r.start();
+            try (Recording r2 = new Recording()){
+                r2.start();
+                r2.stop();
+            }
             r.stop();
             try (EventStream es = EventStream.openRepository()) {
                 es.setStartTime(Instant.EPOCH);