Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NullPointerException: Inflater has been closed On InputStreamReader

I have the following problem:

When I load the resource from the project all works fine, but when I put it on a .jar and try to load I get an exception.

The code is:

InputStreamReader reader =
    new InputStreamReader(
        this.getClass().getResource(fileName).openStream())  
CsvReader stream = new CsvReader(reader);  
try {  
    while (stream.readRecord()) {  
        line = stream.getRawRecord();  
        //DO SOMETHING...  
    }  
}catch (Exception e) {  
    System.err.println(e.getMessage());  
    e.printStackTrace();  
} finally {  
    stream.close();  
}

And the stackTrace is:

    Inflater has been closed java.lang.NullPointerException: Inflater has been closed
 at java.util.zip.Inflater.ensureOpen(Inflater.java:364)
 at java.util.zip.Inflater.inflate(Inflater.java:237)
 at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:135)
 at java.io.FilterInputStream.read(FilterInputStream.java:116)
 at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
 at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
 at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
 at java.io.InputStreamReader.read(InputStreamReader.java:167)
 at utils.csvreader.CsvReader.checkDataLength(CsvReader.java:1198)
 at utils.csvreader.CsvReader.readRecord(CsvReader.java:604)

The problem happens on stream.getRawRecord(). I also tried with BufferedReader with same result on readLine();

Any ideas?

like image 361
Yhonny Avatar asked Jan 14 '11 21:01

Yhonny


1 Answers

This can be bug in the Java. I had a similar problem, described here: https://issues.apache.org/jira/browse/FELIX-1032

Is your application running with some special class loader settings?

like image 103
Martin Ždila Avatar answered Nov 10 '22 07:11

Martin Ždila