Java.lang.NullPointerException: Inflater closed In InputStreamReader

I have the following problem:

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

The code:

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 stackTrace:

  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 occurs on stream.getRawRecord() . I also tried with BufferedReader with the same result on readLine();

Any ideas?

+6
java inputstream jar
source share
2 answers

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

Does your application work with some special classloaders?

+1
source share

Downloading a resource from a project means that you are not dealing with zip (jar is zip), so InputStreamReader allows the file you want to read.

My guess is that InputStreamReader allows a null or incorrect file when working with a bank. Log vars to asure

-one
source share

All Articles