src/jdk.jfr/share/classes/jdk/jfr/internal/WriteableUserPath.java
changeset 55256 3b22c7e00573
parent 50113 caf115bb98ad
equal deleted inserted replaced
55255:d49b72808414 55256:3b22c7e00573
    48  */
    48  */
    49 public final class WriteableUserPath {
    49 public final class WriteableUserPath {
    50     private final AccessControlContext controlContext;
    50     private final AccessControlContext controlContext;
    51     private final Path original;
    51     private final Path original;
    52     private final Path real;
    52     private final Path real;
    53     private final String text;
    53     private final String realPathText;
       
    54     private final String originalText;
    54 
    55 
    55     // Not to ensure security, but to help
    56     // Not to ensure security, but to help
    56     // against programming errors
    57     // against programming errors
    57     private volatile boolean inPrivileged;
    58     private volatile boolean inPrivileged;
    58 
    59 
    66         }
    67         }
    67         // will throw if non-writeable
    68         // will throw if non-writeable
    68         BufferedWriter fw = Files.newBufferedWriter(path);
    69         BufferedWriter fw = Files.newBufferedWriter(path);
    69         fw.close();
    70         fw.close();
    70         this.original = path;
    71         this.original = path;
       
    72         this.originalText = path.toString();
    71         this.real = path.toRealPath();
    73         this.real = path.toRealPath();
    72         this.text = real.toString();
    74         this.realPathText = real.toString();
    73     }
    75     }
    74 
    76 
    75     /**
    77     /**
    76      * Returns a potentially malicious path where the user may have implemented
    78      * Returns a potentially malicious path where the user may have implemented
    77      * their own version of Path. This method should never be called in an
    79      * their own version of Path. This method should never be called in an
    83     public Path getPotentiallyMaliciousOriginal() {
    85     public Path getPotentiallyMaliciousOriginal() {
    84         return original;
    86         return original;
    85     }
    87     }
    86 
    88 
    87     /**
    89     /**
    88      * Returns a string representation of the path.
    90      * Returns a string representation of the real path.
    89      *
    91      *
    90      * @return path as text
    92      * @return path as text
    91      */
    93      */
    92     public String getText() {
    94     public String getRealPathText() {
    93         return text;
    95         return realPathText;
    94     }
    96     }
       
    97 
       
    98     /**
       
    99      * Returns a string representation of the original path.
       
   100      *
       
   101      * @return path as text
       
   102      */
       
   103     public String getOriginalText() {
       
   104         return originalText;
       
   105     }
       
   106 
    95 
   107 
    96     /**
   108     /**
    97      * Returns a potentially malicious path where the user may have implemented
   109      * Returns a potentially malicious path where the user may have implemented
    98      * their own version of Path. This method should never be called in an
   110      * their own version of Path. This method should never be called in an
    99      * unsafe context and the Path value should never be passed along to other
   111      * unsafe context and the Path value should never be passed along to other