1103
Phase: Implementation
If one breaks from a loop or function by throwing an exception, make sure that cleanup happens
or that you should exit the program. Use throwing exceptions sparsely.
Demonstrative Examples
Example 1:
The following example demonstrates the weakness.
Example Language: Java (Bad)
public class foo {
public static final void main( String args[] ) {
boolean returnValue;
returnValue=doStuff();
}
public static final boolean doStuff( ) {
boolean threadLock;
boolean truthvalue=true;
try {
while(
//check some condition
) {
threadLock=true; //do some stuff to truthvalue
threadLock=false;
}
}
catch (Exception e){
System.err.println("You did something bad");
if (something) return truthvalue;
}
return truthvalue;
}
}
In this case, a thread might be left locked accidentally.
MemberOf Relationships
This MemberOf relationships table shows additional CWE Catgeories and Views that reference this
weakness as a member. This information is often useful in understanding where a weakness fits
within the context of external information sources.
Nature Type ID Name Page
MemberOf 851 The CERT Oracle Secure Coding Standard for Java
(2011) Chapter 8 - Exceptional Behavior (ERR)
844 2365
MemberOf 880 CERT C++ Secure Coding Section 12 - Exceptions and
Error Handling (ERR)
868 2379
MemberOf 961 SFP Secondary Cluster: Incorrect Exception Behavior 888 2399
MemberOf 1141 SEI CERT Oracle Secure Coding Standard for Java -
Guidelines 07. Exceptional Behavior (ERR)
1133 2448
MemberOf 1181 SEI CERT Perl Coding Standard - Guidelines 03.
Expressions (EXP)
1178 2466
MemberOf 1416 Comprehensive Categorization: Resource Lifecycle
Management
1400 2545
Taxonomy Mappings
Mapped Taxonomy Name Node ID Fit Mapped Node Name
CLASP Improper cleanup on thrown exception
The CERT Oracle Secure
Coding Standard for Java
(2011)
ERR03-J Restore prior object state on method
failure
CWE Version 4.14
CWE-462: Duplicate Key in Associative List (Alist)
CWE-462: Duplicate Key in Associative List (Alist)