OutputStreamToInputStream NPE with explicit subclassing.

14 views
Skip to first unread message

Davide Simonetti

unread,
Mar 28, 2011, 10:27:17 AM3/28/11
to io-t...@googlegroups.com
An user recently sent me an example of a simple code that is not working.

public class MyOutputStream extends OutputStreamToInputStream<Void> {
private MyType myType;
             public MyOutputStream(MyType myType) {
      this.myType = myType;
}

@Override
protected Void doRead(InputStream istream) throws Exception {
myType.doSomething();
return null;
}
}
This code generates a NPE when myType.doSomething() is invoked. This is because the doRead thread is started before the constructor of the class finish (thus myType is still null).
For now only anonymous subclassing was considered. The code should be refactored to work around this problem. In future releases there will be a workaround.

Arnold Maderthaner

unread,
Apr 4, 2011, 7:51:13 AM4/4/11
to io-tools
Is there any timeframe when this bug will be fixed ?

yours

Arnold

Davide Simonetti

unread,
Apr 4, 2011, 10:18:45 AM4/4/11
to io-t...@googlegroups.com
Hi Arnold.
This bug has been fixed Saturday on trunk, however the fix hasn't been extensively tested. You can check out the new class at:
http://io-tools.googlecode.com/svn/trunk/easystream/src/main/java/com/gc/iotools/stream/os/OutputStreamToInputStream.java
or via standard svn checkout.
Now it should be possible to subclass it, and the doRead() should be called only when some data is written to the OutputStream, or when the stream it is closed. Let me know how it is working.
For the complete release of the fix (and the deploy on repo1.maven.org) we currently have no plan. I can say that each 3/4 months the code is released due to new features or stopper bugs. At the moment there are some other pending bugs (in wazformat) that have already been fixed on trunk. I think a new release might be around for the middle of may.
In the meanwhile you can import the class in your code. It's bsd license. You can do whatever you want with that.
Cheers!
Davide
Reply all
Reply to author
Forward
0 new messages