On Tue, 21 Jul 2026 21:41:28 GMT, Phil Race <[email protected]> wrote:

>> src/java.desktop/share/classes/com/sun/media/sound/SoftAbstractResampler.java
>>  line 101:
>> 
>>> 99:             if (stream == null) {
>>> 100:                 throw new IOException("null stream");
>>> 101:             }
>> 
>> This method is used in SoftVoice.processControlLogic and if IOException is 
>> thrown in this place it is catched in 
>> https://github.com/openjdk/jdk/blob/a1ff7b16d40f543add5f815da8a80bdd1dc86224/src/java.desktop/share/classes/com/sun/media/sound/SoftVoice.java#L622,
>>  so initialization of osc_stream is skipped and it can cause NPE later?
>> 
>> It also would be good to check how the osc.getChannels() a few lines above 
>> will work if the stream inside of osc is null(was not open)? Possibly this 
>> can be validated by some unit test?
>
> I've added null checks before de-refing in osc_stream in SoftVoice.java
> 
> The getChannels() call you cite is presumably the one a few lines below (line 
> 628) not above. I don't know that it is needed but I've made the 
> implementation of it return "1" if getFormat() is null. I think in general as 
> a policy  it ought not to be possible to reach paths which require a stream 
> if there is none.

Seems that is not enough. osc_stream can be initialized before to non-null 
value(it is never reassigned back to null). And when IOException will be thrown 
in the "SoftVoice.processControlLogic->resampler.open()" we can get non-null 
osc_stream and resampler with null stream, when this resampler will be used an 
NPE can occur.

>  Exception in thread "JitterCorrector" java.lang.NullPointerException:
    Cannot invoke "com.sun.media.sound.AudioFloatInputStream.close()" because 
"this.stream" is null
    at 
com.sun.media.sound.SoftAbstractResampler$ModelAbstractResamplerStream.close(SoftAbstractResampler.java:387)
    at com.sun.media.sound.SoftVoice.processControlLogic(SoftVoice.java:590)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/31299#discussion_r3669557143

Reply via email to