CRITICAL
Rule Definition
A call to 'super.finalize()' ensures the finalize behavior will still work.
Remediation
Review the Method's definition.
Violation Code Sample
protected void finalize() { SomeSystemResourcesRelease(); //Violation: no call to super.finalize(); } --------------------------------------------------------------------- protected void finalize() { super.finalize(); // Violation as the call should be done at end of the method SomeSystemResourcesRelease(); }
Fixed Code Sample
protected void finalize() { releaseSomeResources(); super.finalize(); } We can also add call to super.finalize() in a finally block: protected void finalize()throws Throwable {try { releaseSomeResources(); } catch(Throwable th) { throw th; } finally { super.finalize(); }
Reference
https://cwe.mitre.org/data/definitions/568.html
Related Technologies
JEE
Technical Criterion
Programming Practices - OO Inheritance and Polymorphism
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.