6962419: TEST_BUG: java_io tests fails in samevm mode
Reviewed-by: ohair, sherman
diff --git a/test/java/io/RandomAccessFile/ReadLine.java b/test/java/io/RandomAccessFile/ReadLine.java
index 879926f..1d63ce0 100644
--- a/test/java/io/RandomAccessFile/ReadLine.java
+++ b/test/java/io/RandomAccessFile/ReadLine.java
@@ -33,26 +33,30 @@
public static void main(String args[]) throws Exception {
File fn = new File("x.ReadLine");
RandomAccessFile raf = new RandomAccessFile(fn,"rw");
- String line;
- int ctr = 1;
- String expected;
+ try {
+ String line;
+ int ctr = 1;
+ String expected;
- raf.writeBytes
- ("ln1\rln2\r\nln3\nln4\rln5\r\nln6\n\rln8\r\rln10\n\nln12\r\r\nln14");
- raf.seek(0);
+ raf.writeBytes
+ ("ln1\rln2\r\nln3\nln4\rln5\r\nln6\n\rln8\r\rln10\n\nln12\r\r\nln14");
+ raf.seek(0);
- while ((line=raf.readLine()) != null) {
- if ((ctr == 7) || (ctr == 9) ||
- (ctr == 11) || (ctr == 13)) {
- expected = "";
- } else {
- expected = "ln" + ctr;
+ while ((line=raf.readLine()) != null) {
+ if ((ctr == 7) || (ctr == 9) ||
+ (ctr == 11) || (ctr == 13)) {
+ expected = "";
+ } else {
+ expected = "ln" + ctr;
+ }
+ if (!line.equals(expected)) {
+ throw new Exception("Expected \"" + expected + "\"" +
+ ", read \"" + line + "\"");
+ }
+ ctr++;
}
- if (!line.equals(expected)) {
- throw new Exception("Expected \"" + expected + "\"" +
- ", read \"" + line + "\"");
- }
- ctr++;
+ } finally {
+ raf.close();
}
System.err.println("Successfully completed test!");
}