Below code is the serialize method of org.springframework.util.SerializationUtils(spring-core.3.2.1.jar). As you can see, there is no oos.close method. Is it OK not to call close method?
In this particular case, it's okay - the two streams involved (the ObjectOutputStream
and ByteArrayOutputStream
) don't use any unmanaged resources (file handles, network handles) etc so it's okay for the garbage collector to just take care of it.
Personally I usually close even streams like that, just to be in the right habits and in case someone changes the type of the stream to one that does have unmanaged resources, but I don't think it really counts as a bug in this case.
See more on this question at Stackoverflow