Regis wrote:
Kyle Cho (JIRA) wrote:
[ https://issues.apache.org/jira/browse/HARMONY-6216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12721474#action_12721474 ]
Kyle Cho commented on HARMONY-6216:
-----------------------------------

found that the patch breaks the following test case.

  public static void main(String args[])
  {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String line = null;
    try {
      line = reader.readLine();
    } catch (IOException e) {
      e.printStackTrace();
    }
    System.out.println(line);
  }

problem with reading zero-length file
-------------------------------------

                Key: HARMONY-6216
                URL: https://issues.apache.org/jira/browse/HARMONY-6216
            Project: Harmony
         Issue Type: Bug
         Components: Classlib
   Affects Versions: 5.0M10
        Environment: RedHat EL 5 x86
           Reporter: Kyle Cho
           Priority: Minor
        Attachments: HARMONY-6216.diff


The following test fails:
----------------------- proc.java starts ------------------
import java.io.*;
class proc {
        public static void main(String args[])
        {
                String s0 = "cpu";
                String s = null;
String file= "/proc/cpuinfo"; // zero-length special file
                try {
BufferedReader br = new BufferedReader(new FileReader(new File(file)));
                        do {
                                if ((s = br.readLine()) == null) {
                                        break;
                                }
                                System.out.println("s: "+s);
                        } while (s.indexOf(s0) == -1);
                } catch (IOException ioe) {
                        ioe.printStackTrace();
                }
                System.out.println("s: "+s);
        }
}
----------------------- proc.java ends -------------------
java.io.IOException
at org.apache.harmony.luni.platform.OSFileSystem.seek(OSFileSystem.java:110)
        at java.io.FileInputStream.available(FileInputStream.java:149)
        at java.io.InputStreamReader.read(InputStreamReader.java:249)
        at java.io.BufferedReader.fillbuf(BufferedReader.java:107)
        at java.io.BufferedReader.readLine(BufferedReader.java:318)
        at proc.main(proc.java:11)
s: null


Hi gays,

Sorry guys, my fingers just out of control, no mean to offend.
Sorry again.....


I have investigated this issue for a while, but can't find a good way to resolve it :(

It is started by Harmony can't read zero-length special file in Linux, like file /proc/cpuinfo. Harmony InputStreamReader used available() before reading chars:

if ((in.available() == 0) && (out.position() > offset)) {
    // we could return the result without blocking read
    break;
}

but available() can't work with zero-length special file, throws IOException (so do RI). So I removed the whole "if" statement, it break read from stdin, I realized that the "if" is just for stdin.

For stdin, read will return immediately once has read some bytes, don't need to try to fill the given buffer full. But for FileInputStream, read operation will try its best to fill the buffer. That's different.

I have no idea how to combine these two behaviors in one read methods without using available(). Anyone have ideas or suggestions?



--
Best Regards,
Regis.

Reply via email to