1

Use Eclipse (2021-06, 4.20.0) run-config settings in "Common" tab to attach a csv file to standard input. Attach a CSV parser to standard input.

Pulling CSV records from the parser gets all the file content, but doesn't detect EOF. This happens with both opencsv-5.5.2, and apache-csv-1.9.0 (and with my company's legacy csv parser).

E.g. with opencsv:

var isr = new InputStreamReader(System.in);
var br = new BufferedReader(isr);
var reader = new CSVReader(isr /* or br */);
while ( (csv_record = reader.readNext()) != null) {
    // foo
}

hangs in FileInputStream.readBytes after reading all the csv lines. Call stack:

Thread [main] (Suspended)   
    owns: BufferedInputStream  (id=75)  
    owns: InputStreamReader  (id=22)    
    FileInputStream.readBytes(byte[], int, int) line: not available [native method] 
    FileInputStream.read(byte[], int, int) line: 279    
    BufferedInputStream.read1(byte[], int, int) line: 290   
    BufferedInputStream.read(byte[], int, int) line: 351    
    StreamDecoder.readBytes() line: 284 
    StreamDecoder.implRead(char[], int, int) line: 326  
    StreamDecoder.read(char[], int, int) line: 178  
    InputStreamReader.read(char[], int, int) line: 185  
    BufferedReader.fill() line: 161 
    BufferedReader.read() line: 182 
    CSVReader.isClosed() line: 399  
    CSVReader.getNextLine() line: 343   
    CSVReader.primeNextRecord() line: 235   
    CSVReader.flexibleRead(boolean, boolean) line: 598  
    CSVReader.readNext() line: 204  
    Main.main(String[]) line: 48    

All csv parsers hang in FileInputStream.readBytes, with similar stack traces.

All variants run fine outside eclipse, using redirection.

Is this a known Eclipse bug? I searched but found nothing.

Is there any known work-around?

greg-449
  • 109,219
  • 232
  • 102
  • 145
Underhill
  • 408
  • 2
  • 13
  • Eclipse does not run your code, the Java VM you chose runs your code. It's very likely that you did something wrong. Show how to reproduce your issue so that one can help you (the code you showed is not enough to reproduce your issue). It is unclear why you used `System.in` (which will probably never be closed) instead of a separate `InputStream` for this purpose. – howlger Nov 09 '21 at 18:15
  • 1
    This looks like [this bug](https://bugs.eclipse.org/bugs/show_bug.cgi?id=513713). which is not resolved. Best to avoid redirect System.in like this and specifying the file name directly. – greg-449 Nov 09 '21 at 19:25
  • @howlger 1. Eclipse re-wires stdin, Java VM running the code isn't relevant. 2. When stdin is redirected from a file System.in is supposed to be closed at EOF (apparently Eclipse isn't doing that, see the bug report). 3. System.in is used when the program is intended to be run using redirection. This is standard, should be clear. – Underhill Nov 09 '21 at 20:31
  • @Underhill Indeed, greg-449 knew it even though a reproducible example is missing. – howlger Nov 10 '21 at 07:55

1 Answers1

1

Hat-tip to greg-449, this is almost certainly an eclipse bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=513713

Underhill
  • 408
  • 2
  • 13
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Tyler2P Nov 09 '21 at 21:53
  • 1
    @Tyler2P That's a link to the bug report proving it's a known issue without a knowing workaround. So, the link is here enough. Copying content from elsewhere is bad because the original content is usually better maintained than a Stack Overflow answer. Because Stack Overflow answers are easier to find than the original content, this leads to one getting the outdated content first. – howlger Nov 10 '21 at 08:06
  • 1
    You might comment on the bug and help to get it fixed. – howlger Nov 10 '21 at 08:06