Description
You are getting a violation that seems wrong for you for quality rule - Close the outermost stream ASAP .
Observed in CAST AIP
Release | Yes/No |
---|---|
8.3.x |
Observed on RDBMS
RDBMS | Yes/No |
---|---|
CSS |
Step by Step Scenario
- Taking analysis and snapshot
- Observing a violation for 'Close the outermost stream ASAP' that seems to be wrong
Action Plan
Check if you have closed the outermost stream both in the try block and in the finally block as shown in below source code.
Example -private void Writing() throws IOException { DataOutputStream out = null; try { out = new DataOutputStream(new FileOutputStream("data")); out.writeInt(666); out.writeUTF("Hello"); out.close(); //close in the try block out = null; } finally { if (out != null) { out.close(); // close in the finally blcok } }
This will lead to a violation because you are not using the right remediation pattern to close the outputstream as indicated in the remediation section.
You should close it only once in the finally block without closing it in the try block. In other words, you should have instead.
private void correctWriting() throws IOException { DataOutputStream out = null; try { out = new DataOutputStream(new FileOutputStream("data")); out.writeInt(666); out.writeUTF("Hello"); } finally { if (out != null) { out.close(); // FIX } } }
Impact on Analysis Results and Dashboard
Impact of issue: Impact after applying solution: To be decided
Notes/comments
Ticket # 3760