Unreleased resource: stream in activity InvokeAxis2

Hello, Team.

Can anyone explain me why there is no close method called after reading from data source stream inside activity InvokeAxis2?

  1. try {
  2. in = dataSource.getInputStream();
  3. byte[] buf = new byte[in.available()];
  5. String attachVal = Base64Util.encodeToString(buf);
  6. attachKeys.add(attachKey);
  7. attachVals.add(attachVal);
  8. attachTypes.add(attachType);
  9. } catch (Throwable e) {
  10. throw new ConnectorException("Couldn't serialize attachment to string value", e);
  11. }

I'm using Pega 7.2.2. Activity InvokeAxis2 is located in Rule-Connect-SOAP class. Pega-IntegrationEngine:07-10-27 ruleset.




Keep up to date on this post and subscribe to comments

August 12, 2019 - 7:34am

In general, you should add a finally clause in the code above:

finally {
                        try {
                            if (in != null)
                        } catch ( ex) {
                            oLog.error("Error occured while closing inputstream");


August 12, 2019 - 7:54am
Response to KevinZheng_GCS

Hi, Kevin

Thank you for your reply.

I know how stream closing should be done. I ask, why there is no stream close method call inside Pega OOTB activity? 


August 12, 2019 - 10:48am

Hi Alex,

If you go through java code then you can see, pega is catching all Throwable (catch (Throwable e)) in Catch block. In java , 'Throwable' is the top most class in exception hierarchy. So in all exception scenario, it will throw 'ConnectorException' and exception handling are being done in ConnectorException. No need of 'Closing (Finally)' block.

Java Exception hierarchy:

Hope this will answer your question.



August 13, 2019 - 8:18am
Response to PravinKumar01

Hi, Pravin.

I'm asking why there is no close method for opened stream?

It should be like:

  1. try {
  2. InputStream in = dataSource.getInputStream();
  3. byte[] buf = new byte[in.available()];
  5. } catch (Exception e) {
  6. // Handle exception
  7. } finally {
  8. in.close();
  9. }

Not closed stream can lead to memory leaks.


August 13, 2019 - 2:40pm

Hi Alex,

Try with resources is also an alternative approach to do the same in which there is no requirement to close the streams explicitly by calling close() method. 

Could you please let us know about the step containing this code snippet under InvokeAxis2 activity?


August 14, 2019 - 12:31am
Response to goela1

Hi, Goela

There is no try with resources statement in code.

It is step 16.