Hi all,
Opening a java.io.RandomAccessFile in read-only mode with a security
manager in force requires the permission to write file descriptors.
The attached patch fixes. Anyone mind if I commit?
Cheers,
Gary
------------------------------------------------------------------------
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.5764
diff -u -r1.5764 ChangeLog
--- ChangeLog 5 Dec 2005 13:25:00 -0000 1.5764
+++ ChangeLog 5 Dec 2005 14:36:19 -0000
@@ -1,3 +1,9 @@
+2005-11-18 Gary Benson <address@hidden>
+
+ * java/io/RandomAccessFile.java (RandomAccessFile): Don't create
+ DataOutputStream for read-only files to avoid unnecessary security
+ manager check.
+
2005-12-05 Mark Wielaard <address@hidden>
Fixes bug classpath/25257
Index: java/io/RandomAccessFile.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/RandomAccessFile.java,v
retrieving revision 1.47
diff -u -r1.47 RandomAccessFile.java
--- java/io/RandomAccessFile.java 2 Jul 2005 20:32:38 -0000 1.47
+++ java/io/RandomAccessFile.java 5 Dec 2005 14:36:19 -0000
@@ -124,7 +124,10 @@
ch = FileChannelImpl.create(file, fdmode);
fd = new FileDescriptor(ch);
- out = new DataOutputStream (new FileOutputStream (fd));
+ if ((fdmode & FileChannelImpl.WRITE) != 0)
+ out = new DataOutputStream (new FileOutputStream (fd));
+ else
+ out = null;
in = new DataInputStream (new FileInputStream (fd));
}
@@ -766,6 +769,9 @@
*/
public void write (int oneByte) throws IOException
{
+ if (out == null)
+ throw new IOException("Bad file descriptor");
+