aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2004-06-27 19:42:19 +0000
committerMark Wielaard <mark@gcc.gnu.org>2004-06-27 19:42:19 +0000
commit01036503d173b294661f06aff8146b0e10c673b1 (patch)
tree20550b6ae14e7eb6b74be814db934118a8d55153
parentce6230c4060eb099accc315bd3f6ff88813d2e7b (diff)
downloadgcc-01036503d173b294661f06aff8146b0e10c673b1.zip
gcc-01036503d173b294661f06aff8146b0e10c673b1.tar.gz
gcc-01036503d173b294661f06aff8146b0e10c673b1.tar.bz2
FilePermission.java (usingPerms): Removed.
* java/io/FilePermission.java (usingPerms): Removed. (actionsString): Made final. (cachePerms): Renamed to checkPerms. (checkPerms): Renamed from cachePerms. Call trim() and toLowerCase() on action String. (FilePermission): Check arguments, call checkPerms(). (equals): Remove cachePerms() call. (implies): Likewise. From-SVN: r83743
-rw-r--r--libjava/ChangeLog11
-rw-r--r--libjava/java/io/FilePermission.java50
2 files changed, 37 insertions, 24 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index ae95f7b..5f4565c 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,14 @@
+2004-06-27 Mark Wielaard <mark@klomp.org>
+
+ * java/io/FilePermission.java (usingPerms): Removed.
+ (actionsString): Made final.
+ (cachePerms): Renamed to checkPerms.
+ (checkPerms): Renamed from cachePerms. Call trim() and toLowerCase()
+ on action String.
+ (FilePermission): Check arguments, call checkPerms().
+ (equals): Remove cachePerms() call.
+ (implies): Likewise.
+
2004-06-27 Mark Wielaard <mark@klomp.org>
* gnu/java/net/protocol/http/Connection.java (userAgent): New static
diff --git a/libjava/java/io/FilePermission.java b/libjava/java/io/FilePermission.java
index c34a2ec..7d86c29 100644
--- a/libjava/java/io/FilePermission.java
+++ b/libjava/java/io/FilePermission.java
@@ -1,5 +1,5 @@
/* java.lang.FilePermission
- Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -46,23 +46,21 @@ public final class FilePermission extends Permission implements Serializable
private static final String CURRENT_DIRECTORY =
System.getProperty("user.dir");
- private boolean usingPerms = false;
private boolean readPerm = false;
private boolean writePerm = false;
private boolean executePerm = false;
private boolean deletePerm = false;
- private String actionsString;
+ private final String actionsString;
- private void cachePerms()
+ // Checks and caches the actions
+ private void checkPerms() throws IllegalArgumentException
{
- // While race conditions could occur, they don't matter at all.
-
String action;
int i = actionsString.indexOf(',');
int startI = 0;
while(i != -1)
{
- action = actionsString.substring(startI,i);
+ action = actionsString.substring(startI,i).trim().toLowerCase();
if(action.equals("read"))
readPerm = true;
else if(action.equals("write"))
@@ -71,12 +69,14 @@ public final class FilePermission extends Permission implements Serializable
executePerm = true;
else if(action.equals("delete"))
deletePerm = true;
+ else
+ throw new IllegalArgumentException("Unknown action: " + action);
startI = i+1;
i = actionsString.indexOf(',',startI);
}
- action = actionsString.substring(startI);
+ action = actionsString.substring(startI).trim().toLowerCase();
if(action.equals("read"))
readPerm = true;
else if(action.equals("write"))
@@ -85,19 +85,30 @@ public final class FilePermission extends Permission implements Serializable
executePerm = true;
else if(action.equals("delete"))
deletePerm = true;
+ else
+ throw new IllegalArgumentException("Unknown action: " + action);
}
- /** Create a new FilePermission.
- ** @param pathExpression an expression specifying the paths this
- ** permission represents.
- ** @param actionsString a comma-separated list of the actions this
- ** permission represents.
- ** FIXME: what to do when the file string is malformed?
- **/
+ /*
+ * Create a new FilePermission.
+ *
+ * @param pathExpression an expression specifying the paths this
+ * permission represents.
+ * @param actionsString a comma-separated list of the actions this
+ * permission represents. The actions must be "read", "write",
+ * "execute" and/or "delete".
+ *
+ * FIXME: what to do when the file string is malformed?
+ */
public FilePermission(String pathExpression, String actionsString)
{
super(pathExpression);
+ if (pathExpression == null)
+ throw new NullPointerException("pathExpression");
+ if (actionsString == null)
+ throw new IllegalArgumentException("actionsString");
this.actionsString = actionsString;
+ checkPerms();
}
/** Get the actions this FilePermission supports.
@@ -132,10 +143,6 @@ public final class FilePermission extends Permission implements Serializable
if(!(o instanceof FilePermission))
return false;
FilePermission p = (FilePermission)o;
- if(!usingPerms)
- cachePerms();
- if(!p.usingPerms)
- p.cachePerms();
String f1 = getName();
String f2 = p.getName();
@@ -283,11 +290,6 @@ public final class FilePermission extends Permission implements Serializable
break;
}
- if(!usingPerms)
- cachePerms();
- if(!fp.usingPerms)
- fp.cachePerms();
-
if(readPerm && !fp.readPerm)
return false;
if(writePerm && !fp.writePerm)