Dataset Viewer
Auto-converted to Parquet Duplicate
language
large_string
page_id
int64
page_url
large_string
chapter
int64
section
int64
rule_id
large_string
title
large_string
intro
large_string
noncompliant_code
large_string
compliant_solution
large_string
risk_assessment
large_string
breadcrumb
large_string
java
88,487,763
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487763
3
18
CON50-J
Do not assume that declaring a reference volatile guarantees safe publication of the members of the referenced object
According to the Java Language Specification , §8.3.1.4, " volatile Fields" [ JLS 2013 ], A field may be declared volatile , in which case the Java Memory Model ensures that all threads see a consistent value for the variable ( §17.4 ). This safe publication guarantee applies only to primitive fields and object referen...
final class Foo { private volatile int[] arr = new int[20]; public int getFirst() { return arr[0]; } public void setFirst(int n) { arr[0] = n; } // ... } final class Foo { private volatile Map<String, String> map; public Foo() { map = new HashMap<String, String>(); // Load some use...
final class Foo { private final AtomicIntegerArray atomicArray = new AtomicIntegerArray(20); public int getFirst() { return atomicArray.get(0); } public void setFirst(int n) { atomicArray.set(0, 10); } // ... } final class Foo { private int[] arr = new int[20]; public synchronized int ...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 18. Concurrency (CON)
java
88,487,832
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487832
3
18
CON51-J
Do not assume that the sleep(), yield(), or getState() methods provide synchronization semantics
According to the Java Language Specification , §17.3, "Sleep and Yield" [ JLS 2013 ], It is important to note that neither Thread.sleep nor Thread.yield have any synchronization semantics. In particular, the compiler does not have to flush writes cached in registers out to shared memory before a call to Thread.sleep or...
final class ControlledStop implements Runnable { private boolean done = false; @Override public void run() { while (!done) { try { Thread.sleep(1000); } catch (InterruptedException e) { // Reset interrupted status  Thread.currentThread().interrupt(); } } } public voi...
final class ControlledStop implements Runnable { private volatile boolean done = false; @Override public void run() { //... } // ... } final class ControlledStop implements Runnable { @Override public void run() { // Record current thread, so others can interrupt it myThread = currentThread();...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 18. Concurrency (CON)
java
88,487,842
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487842
3
18
CON52-J
Document thread-safety and use annotations where applicable
The Java language annotation facility is useful for documenting design intent. Source code annotation is a mechanism for associating metadata with a program element and making it available to the compiler, analyzers, debuggers, or Java Virtual Machine (JVM) for examination. Several annotations are available for documen...
null
null
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 18. Concurrency (CON)
java
88,487,756
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487756
2
1
DCL00-J
Prevent class initialization cycles
According to The Java Language Specification (JLS), §12.4, "Initialization of Classes and Interfaces" [ JLS 2005 ]: Initialization of a class consists of executing its static initializers and the initializers for static fields (class variables) declared in the class. Therefore, the presence of a static field triggers t...
public class Cycle { private final int balance; private static final Cycle c = new Cycle(); private static final int deposit = (int) (Math.random() * 100); // Random deposit public Cycle() { balance = deposit - 10; // Subtract processing fee } public static void main(String[] args) { System.out.pr...
public class Cycle { private final int balance; private static final int deposit = (int) (Math.random() * 100); // Random deposit private static final Cycle c = new Cycle(); // Inserted after initialization of required fields public Cycle() { balance = deposit - 10; // Subtract processing fee } public...
## Risk Assessment Initialization cycles may lead to unexpected results. Rule Severity Likelihood Detectable Repairable Priority Level DCL00-J Low Unlikely Yes No P2 L3
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 01. Declarations and Initialization (DCL)
java
88,487,448
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487448
2
1
DCL01-J
Do not reuse public identifiers from the Java Standard Library
Do not reuse the names of publicly visible identifiers, public utility classes, interfaces, or packages in the Java Standard Library. When a developer uses an identifier that has the same name as a public class, such as Vector , a subsequent maintainer might be unaware that this identifier does not actually refer to ja...
class Vector { private int val = 1; public boolean isEmpty() { if (val == 1) { // Compares with 1 instead of 0 return true; } else { return false; } } // Other functionality is same as java.util.Vector } // import java.util.Vector; omitted public class VectorUser { public static vo...
class MyVector { //Other code } ## Compliant Solution (Class Name) This compliant solution uses a different name for the class, preventing any potential shadowing of the class from the Java Standard Library: #ccccff class MyVector { //Other code } When the developer and organization control the original shadowed cla...
## Risk Assessment Public identifier reuse decreases the readability and maintainability of code. Rule Severity Likelihood Detectable Repairable Priority Level DCL01-J Low Unlikely Yes No P2 L3 Automated Detection An automated tool can easily detect reuse of the set of names representing public classes or interfaces fr...
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 01. Declarations and Initialization (DCL)
java
88,487,681
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487681
2
1
DCL02-J
Do not modify the collection's elements during an enhanced for statement
The enhanced for statement is designed for iteration through Collections and arrays . The Java Language Specification (JLS) provides the following example of the enhanced for statement in §14.14.2, "The Enhanced for Statement" [ JLS 2014 ]: The enhanced for statement is equivalent to a basic for statement of the form: ...
List<Integer> list = Arrays.asList(new Integer[] {13, 14, 15}); boolean first = true; System.out.println("Processing list..."); for (Integer i: list) { if (first) { first = false; i = new Integer(99); } System.out.println(" New item: " + i); // Process i } System.out.println("Modified list?"); for (In...
// ... for (final Integer i: list) { if (first) { first = false; i = new Integer(99); // compiler error: variable i might already have been assigned } // ... // ...   for (final Integer i: list) { Integer item = i; if (first) { first = false; item = new Integer(99); } System.out.println(" N...
## Risk Assessment Assignments to the loop variable of an enhanced for loop ( for-each idiom) fail to affect the overall iteration order or the iterated collection or array. This can lead to programmer confusion, and can leave data in a fragile or inconsistent state. Rule Severity Likelihood Detectable Repairable Prior...
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 01. Declarations and Initialization (DCL)
java
88,487,660
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487660
3
1
DCL50-J
Use visually distinct identifiers
Use visually distinct identifiers that are unlikely to be misread during development and review of code. Depending on the fonts used, certain characters are visually similar or even identical and can be misinterpreted. Consider the examples in the following table. Misleading characters Intended Character Could Be Mista...
int stem; // Position near the front of the boat /* ... */ int stern; // Position near the back of the boat public class Visual { public static void main(String[] args) { System.out.println(11111 + 1111l); } } int[] array = new int[3]; void exampleFunction() { array[0] = 2719; array[1] = 4435; array[2...
int bow; // Position near the front of the boat /* ... */ int stern; // Position near the back of the boat public class Visual { public static void main(String[] args) { System.out.println(11111 + 1111L); } } int[] array = new int[3]; void exampleFunction() { array[0] = 2719; array[1] = 4435; array[2...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,396
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487396
3
1
DCL51-J
Do not shadow or obscure identifiers in subscopes
Reuse of identifier names in subscopes leads to obscuration or shadowing. Reused identifiers in the current scope can render those defined elsewhere inaccessible. Although the Java Language Specification (JLS) [ JLS 2013 ] clearly resolves any syntactic ambiguity arising from obscuring or shadowing, such ambiguity burd...
class MyVector { private int val = 1; private void doLogic() { int val; //... } } class MyVector { private int i = 0; private void doLogic() { for (i = 0; i < 10; i++) {/* ... */} for (int i = 0; i < 20; i++) {/* ... */} } } ## Noncompliant Code Example (Field Shadowing) ## This noncom...
class MyVector { private int val = 1; private void doLogic() { int newValue; //... } } class MyVector { private void doLogic() { for (int i = 0; i < 10; i++) {/* ... */} for (int i = 0; i < 20; i++) {/* ... */} } } ## Compliant Solution (Field Shadowing) This compliant solution eliminate...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,521
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487521
3
1
DCL52-J
Do not declare more than one variable per declaration
Declaring multiple variables in a single declaration could cause confusion about the types of variables and their initial values. In particular, do not declare any of the following in a single declaration: Variables of different types A mixture of initialized and uninitialized variables In general, you should declare e...
int i, j = 1; public class Example<T> { private T a, b, c[], d; public Example(T in) { a = in; b = in; c = (T[]) new Object[10]; d = in; } } public String toString() { return a.toString() + b.toString() + c.toString() + d.toString(); } // Correct functional implementation public St...
int i = 1; // Purpose of i... int j = 1; // Purpose of j... int i = 1, j = 1; public class Example<T> { private T a; // Purpose of a... private T b; // Purpose of b... private T[] c; // Purpose of c[]... private T d; // Purpose of d... public Example(T in){ a = in; b = in; c = (T[]) new...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,517
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487517
3
1
DCL53-J
Minimize the scope of variables
Scope minimization helps developers avoid common programming errors, improves code readability by connecting the declaration and actual use of a variable, and improves maintainability because unused variables are more easily detected and removed. It may also allow objects to be recovered by the garbage collector more q...
public class Scope { public static void main(String[] args) { int i = 0; for (i = 0; i < 10; i++) { // Do operations } } } public class Foo { private int count; private static final int MAX_COUNT = 10; public void counter() { count = 0; while (condition()) { /* ... */ i...
public class Scope { public static void main(String[] args) { for (int i = 0; i < 10; i++) { // Contains declaration // Do operations } } } public class Foo { private static final int MAX_COUNT = 10; public void counter() { int count = 0; while (condition()) { /* ... */ if (c...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,464
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487464
3
1
DCL54-J
Use meaningful symbolic constants to represent literal values in program logic
Java supports the use of various types of literals, such as integers (5, 2), floating-point numbers (2.5, 6.022e+23), characters ( 'a' , '\n' ), Booleans ( true , false ), and strings ( "Hello\n" ). Extensive use of literals in a program can lead to two problems. First, the meaning of the literal is often obscured or u...
double area(double radius) { return 3.14 * radius * radius; } double volume(double radius) { return 4.19 * radius * radius * radius; } double greatCircleCircumference(double radius) { return 6.28 * radius; } double area(double radius) { return 3.14 * radius * radius; } double volume(double radius) { retur...
private static final double PI = 3.14; double area(double radius) { return PI * radius * radius; } double volume(double radius) { return 4.0/3.0 * PI * radius * radius * radius; } double greatCircleCircumference(double radius) { return 2 * PI * radius; } double area(double radius) { return Math.PI * radius ...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,528
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487528
3
1
DCL55-J
Properly encode relationships in constant definitions
The definitions of constant expressions should be related exactly when the values they express are also related.
public static final int IN_STR_LEN = 18; public static final int OUT_STR_LEN = 20; public static final int VOTING_AGE = 18; public static final int ALCOHOL_AGE = VOTING_AGE + 3; ## Noncompliant Code Example In this noncompliant code example, OUT_STR_LEN must always be exactly two greater than IN_STR_LEN . These defin...
public static final int IN_STR_LEN = 18; public static final int OUT_STR_LEN = IN_STR_LEN + 2; public static final int VOTING_AGE = 18; public static final int ALCOHOL_AGE = 21; ## Compliant Solution ## In this compliant solution, the relationship between the two values is represented in the definitions: #ccccff publ...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,623
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487623
3
1
DCL56-J
Do not attach significance to the ordinal associated with an enum
Java language enumeration types have an ordinal() method that returns the numerical position of each enumeration constant in its class declaration. According to the Java API, Class Enum<E extends Enum<E>> [ API 2011 ], public final int ordinal() returns the ordinal of the enumeration constant (its position in its enum ...
enum Hydrocarbon { METHANE, ETHANE, PROPANE, BUTANE, PENTANE, HEXANE, HEPTANE, OCTANE, NONANE, DECANE; public int getNumberOfCarbons() { return ordinal() + 1; } } ## Noncompliant Code Example This noncompliant code example declares enum Hydrocarbon and uses its ordinal() method to provide the result of th...
enum Hydrocarbon { METHANE(1), ETHANE(2), PROPANE(3), BUTANE(4), PENTANE(5), HEXANE(6), BENZENE(6), HEPTANE(7), OCTANE(8), NONANE(9), DECANE(10); private final int numberOfCarbons; Hydrocarbon(int carbons) { this.numberOfCarbons = carbons; } public int getNumberOfCarbons() { return numberOfCarbons; ...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,795
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487795
3
1
DCL57-J
Avoid ambiguous overloading of variable arity methods
The variable arity (varargs) feature was introduced in JDK v1.5.0 to support methods that accept a variable numbers of arguments. According to the Java SE 6 documentation [ Oracle 2011b ], As an API designer, you should use [variable arity methods] sparingly, only when the benefit is truly compelling. Generally speakin...
class Varargs { private static void displayBooleans(boolean... bool) { System.out.print("Number of arguments: " + bool.length + ", Contents: "); for (boolean b : bool) System.out.print("[" + b + "]"); } private static void displayBooleans(boolean bool1, boolean bool2) { System.out.println("Ove...
class Varargs { private static void displayManyBooleans(boolean... bool) { System.out.print("Number of arguments: " + bool.length + ", Contents: "); for (boolean b : bool) System.out.print("[" + b + "]"); } private static void displayTwoBooleans(boolean bool1, boolean bool2) { System.out.print...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,794
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487794
3
1
DCL58-J
Enable compile-time type checking of variable arity parameter types
A variable arity (aka varargs ) method is a method that can take a variable number of arguments. The method must contain at least one fixed argument. When processing a variable arity method call, the Java compiler checks the types of all arguments, and all of the variable actual arguments must match the variable formal...
double sum(Object... args) { double result = 0.0; for (Object arg : args) { if (arg instanceof Byte) { result += ((Byte) arg).byteValue(); } else if (arg instanceof Short) { result += ((Short) arg).shortValue(); } else if (arg instanceof Integer) { result += ((Integer) arg).int...
double sum(Number... args) { // ... } <T extends Number> double sum(T... args) { // ... } ## Compliant Solution (Number) This compliant solution defines the same method but uses the Number type. This abstract class is general enough to encompass all numeric types, yet specific enough to exclude nonnumeric types. ...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,460
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487460
3
1
DCL59-J
Do not apply public final to constants whose value might change in later releases
The final keyword can be used to specify constant values (that is, values that cannot change during program execution). However, constants that can change over the lifetime of a program should not be declared public final. The Java Language Specification (JLS) [ JLS 2013 ] allows implementations to insert the value of ...
class Foo { public static final int VERSION = 1; // ... } class Bar { public static void main(String[] args) { System.out.println("You are using version " + Foo.VERSION); } } You are using version 1 You are using version 1 ## Noncompliant Code Example In this noncompliant code example, class Foo...
class Foo { private static int version = 1; public static final int getVersion() { return version; } // ... } class Bar { public static void main(String[] args) { System.out.println( "You are using version " + Foo.getVersion()); } } ## Compliant Solution According to §13.4.9, " final Fields...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,472
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487472
3
1
DCL60-J
Avoid cyclic dependencies between packages
Both The Elements of Java Style [ Vermeulen 2000 ] and the JPL Java Coding Standard [ Havelund 2010 ] require that the dependency structure of a package must never contain cycles; that is, it must be representable as a directed acyclic graph (DAG). Eliminating cycles between packages has several advantages: Testing and...
package account; import user.User; public class AccountHolder { private User user; public void setUser(User newUser) {user = newUser;}   synchronized void depositFunds(String username, double amount) { // Use a utility method of User to check whether username exists if (user.exists(username)) { //...
package bank; public interface BankApplication { void depositFunds(BankApplication ba, String username, double amount); double getBalance(String accountNumber); double getUserBalance(String accountNumber); boolean exists(String username); } package account; import bank.BankApplication; // Import from a th...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,369
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487369
3
1
DCL61-J
Do not use raw types
Under Construction This guideline is under construction. Mixing generically typed code with raw typed code is one common source of heap pollution. Prior to Java 5, all code used raw types. Allowing mixing enabled developers to preserve compatibility between non-generic legacy code and newer generic code. Using raw type...
class ListUtility { private static void addToList(List list, Object obj) { list.add(obj); // unchecked warning } public static void main(String[] args) { List<String> list = new ArrayList<String> (); addToList(list, 42); System.out.println(list.get(0)); // throws ClassCastException } } ## Non...
class ListUtility { private static void addToList(List<String> list, String str) { list.add(str); // No warning generated } public static void main(String[] args) { List<String> list = new ArrayList<String> (); addToList(list, "42"); System.out.println(list.get(0)); } } ## Compliant Soluti...
null
SEI CERT Oracle Coding Standard for Java > 3 Recommendations > Rec. 01. Declarations and Initialization (DCL)
java
88,487,809
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487809
2
16
ENV00-J
Do not sign code that performs only unprivileged operations
Java uses code signing as a requirement for granting elevated privileges to code. Many security policies permit signed code to operate with elevated privileges. For example, Java applets can escape the default sandbox restrictions when signed. Consequently, users can grant explicit permissions either to a particular co...
null
null
## Risk Assessment Signing unprivileged code violates the principle of least privilege because it can circumvent security restrictions defined by the security policies of applets and JNLP applications, for example. Rule Severity Likelihood Detectable Repairable Priority Level ENV00-J High Probable No No P6 L2
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 16. Runtime Environment (ENV)
java
88,487,914
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487914
2
16
ENV01-J
Place all security-sensitive code in a single JAR and sign and seal it
In Java SE 6 and later, privileged code must either use the AccessController mechanism or be signed by an owner (or provider) whom the user trusts. Attackers could link privileged code with malicious code if the privileged code directly or indirectly invokes code from another package. Trusted JAR files often contain co...
package trusted; import untrusted.RetValue; public class MixMatch { private void privilegedMethod() throws IOException { try { AccessController.doPrivileged( new PrivilegedExceptionAction<Void>() { public Void run() throws IOException, FileNotFoundException { final FileInputSt...
package trusted; public class MixMatch { // ... } // In the same signed & sealed JAR file: package trusted; class RetValue { int getValue() { return 1; } } Name: trusted/ // Package name Sealed: true // Sealed attribute ## Compliant Solution This compliant solution combines all security-sensitive code...
## Risk Assessment Failure to place all privileged code together in one package and seal the package can lead to mix-and-match attacks. Rule Severity Likelihood Detectable Repairable Priority Level ENV01-J High Probable No No P6 L2
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 16. Runtime Environment (ENV)
java
88,487,852
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487852
2
16
ENV02-J
Do not trust the values of environment variables
Deprecated This guideline has been deprecated. Both environment variables and system properties provide user-defined mappings between keys and their corresponding values and can be used to communicate those values from the environment to a process. According to the Java API [ API 2014 ] java.lang.System class documenta...
String username = System.getenv("USER"); public static void main(String args[]) { if (args.length != 1) { System.err.println("Please supply a user name as the argument"); return; } String user = args[0]; ProcessBuilder pb = new ProcessBuilder(); pb.command("/usr/bin/printenv"); Map<String,String> e...
String username = System.getProperty("user.name"); ## Compliant Solution This compliant solution obtains the user name using the user.name system property. The Java Virtual Machine (JVM), upon initialization, sets this system property to the correct user name, even when the USER environment variable has been set to an...
## Risk Assessment Untrusted environment variables can provide data for injection and other attacks if not properly sanitized . Rule Severity Likelihood Detectable Repairable Priority Level ENV02-J Low Likely Yes No P6 L2
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 16. Runtime Environment (ENV)
java
88,487,671
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487671
2
16
ENV03-J
Do not grant dangerous combinations of permissions
Certain combinations of permissions can produce significant capability increases and should not be granted. Other permissions should be granted only to special code. AllPermission The permission java.security.AllPermission grants all possible permissions to code. This facility was included to reduce the burden of manag...
// Grant the klib library AllPermission grant codebase "file:${klib.home}/j2se/home/klib.jar" { permission java.security.AllPermission; }; protected PermissionCollection getPermissions(CodeSource cs) { PermissionCollection pc = super.getPermissions(cs); pc.add(new ReflectPermission("suppressAccessChecks"));...
grant codeBase "file:${klib.home}/j2se/home/klib.jar", signedBy "Admin" { permission java.io.FilePermission "/tmp/*", "read"; permission java.io.SocketPermission "*", "connect"; }; // Security manager check FilePermission perm = new java.io.FilePermission("/tmp/JavaFile", "read"); AccessController.checkPe...
## Risk Assessment Granting AllPermission to untrusted code allows it to perform privileged operations. Rule Severity Likelihood Detectable Repairable Priority Level ENV03-J High Likely No No P9 L2
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 16. Runtime Environment (ENV)
java
88,487,890
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487890
2
16
ENV04-J
Do not disable bytecode verification
When Java source code is compiled, it is converted into bytecode, saved in one or more class files, and executed by the Java Virtual Machine (JVM). Java class files may be compiled on one machine and executed on another machine. A properly generated class file is said to be conforming . When the JVM loads a class file,...
java -Xverify:none ApplicationName ## Noncompliant Code Example The bytecode verification process runs by default. The -Xverify:none flag on the JVM command line suppresses the verification process. This noncompliant code example uses the flag to disable bytecode verification: #FFcccc java -Xverify:none ApplicationNam...
java -Xverify:all ApplicationName ## Compliant Solution Most JVM implementations perform bytecode verification by default; it is also performed during dynamic class loading. Specifying the -Xverify:all flag on the command line requires the JVM to enable bytecode verification (even when it would otherwise have been sup...
## Risk Assessment Bytecode verification ensures that the bytecode contains many of the security checks mandated by the Java Language Specification . Omitting the verification step could permit execution of insecure Java code. Rule Severity Likelihood Detectable Repairable Priority Level ENV04-J High Likely No No P9 L2
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 16. Runtime Environment (ENV)
java
88,487,615
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487615
2
16
ENV05-J
Do not deploy an application that can be remotely monitored
Java provides several APIs that allow external programs to monitor a running Java program. These APIs also permit the Java program to be monitored remotely by programs on distinct hosts. Such features are convenient for debugging the program or fine-tuning its performance. However, if a Java program is deployed in prod...
${JDK_PATH}/bin/java -agentlib:libname=options ApplicationName ${JDK_PATH}/bin/java -agentlib:jdwp=transport=dt_shmem, address=mysharedmemory ApplicationName ${JDK_PATH}/bin/java -Dcom.sun.management.jmxremote.port=8000 ApplicationName ${JDK_PATH}/bin/java -agentlib:jdwp=transport=dt_socket, server=y,ad...
${JDK_PATH}/bin/java -Djava.security.manager ApplicationName ${JDK_PATH}/bin/java -agentlib:jdwp=transport=dt_socket, server=n,address=9000 ApplicationName ## Compliant Solution This compliant solution starts the JVM without any agents enabled. Avoid using the -agentlib , -Xrunjdwp , and -Xdebug command-line arg...
## Risk Assessment Deploying a Java application with the JVMTI, JPDA, or remote monitoring enabled can allow an attacker to monitor or modify its behavior. Rule Severity Likelihood Detectable Repairable Priority Level ENV05-J High Probable No No P6 L2
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 16. Runtime Environment (ENV)
java
88,487,339
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487339
2
16
ENV06-J
Production code must not contain debugging entry points
According to J2EE Bad Practices: Leftover Debug Code [ Hewlett-Packard 2015 ]: A common development practice is to add "back door" code specifically designed for debugging or testing purposes that is not intended to be shipped or deployed with the application. When this sort of debug code is accidentally left in the ap...
class Stuff { private static final bool DEBUG = False; // Other fields and methods public static void main(String args[]) { Stuff.DEBUG = True; Stuff stuff = new Stuff(); // Test stuff } } ## Noncompliant Code Example In this noncompliant code example, the Stuff class has a main() function that tes...
## Compliant Solution ## A compliant solution simply removes themain()method from theStuffclass, depriving attackers of this entry point.
## Risk Assessment Leaving extra entry points into production code could allow an attacker to gain special access to the program. Rule Severity Likelihood Detectable Repairable Priority Level ENV06-J High Probable No No P6 L2
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 16. Runtime Environment (ENV)
java
88,487,876
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487876
2
7
ERR00-J
Do not suppress or ignore checked exceptions
Programmers often suppress checked exceptions by catching exceptions with an empty or trivial catch block. Each catch block must ensure that the program continues only with valid invariants . Consequently, the catch block must either recover from the exceptional condition, rethrow the exception to allow the next neares...
try { //... } catch (IOException ioe) { ioe.printStackTrace(); } class Foo implements Runnable { public void run() { try { Thread.sleep(1000); } catch (InterruptedException e) { // Ignore } } } ## Noncompliant Code Example ## This noncompliant code example simply prints the exception's...
boolean validFlag = false; do { try { // ...  // If requested file does not exist, throws FileNotFoundException // If requested file exists, sets validFlag to true validFlag = true; } catch (FileNotFoundException e) { // Ask the user for a different file name } } while (validFlag != true); // U...
## Risk Assessment Ignoring or suppressing exceptions can result in inconsistent program state. Rule Severity Likelihood Detectable Repairable Priority Level ERR00-J Low Probable Yes No P4 L3
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 07. Exceptional Behavior (ERR)
java
88,487,679
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487679
2
7
ERR01-J
Do not allow exceptions to expose sensitive information
Failure to filter sensitive information when propagating exceptions often results in information leaks that can assist an attacker's efforts to develop further exploits. An attacker may craft input arguments to expose internal structures and mechanisms of the application. Both the exception message text and the type of...
class ExceptionExample { public static void main(String[] args) throws FileNotFoundException { // Linux stores a user's home directory path in // the environment variable $HOME, Windows in %APPDATA% FileInputStream fis = new FileInputStream(System.getenv("APPDATA") + args[0]); } } try { Fi...
class ExceptionExample { public static void main(String[] args) { File file = null; try { file = new File(System.getenv("APPDATA") + args[0]).getCanonicalFile(); if (!file.getPath().startsWith("c:\\homepath")) { System.out.println("Invalid file"); return; } ...
## Risk Assessment Exceptions may inadvertently reveal sensitive information unless care is taken to limit the information disclosure. Rule Severity Likelihood Detectable Repairable Priority Level ERR01-J Medium Probable No Yes P8 L2
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 07. Exceptional Behavior (ERR)
java
88,487,839
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487839
2
7
ERR02-J
Prevent exceptions while logging data
Exceptions that are thrown while logging is in progress can prevent successful logging unless special care is taken. Failure to account for exceptions during the logging process can cause security vulnerabilities , such as allowing an attacker to conceal critical security exceptions by preventing them from being logged...
try { // ... } catch (SecurityException se) { System.err.println(se); // Recover from exception } ## Noncompliant Code Example ## This noncompliant code example writes a critical security exception to the standard error stream: #FFcccc try { // ... } catch (SecurityException se) { System.err.println(se); // Reco...
try { // ... } catch(SecurityException se) { logger.log(Level.SEVERE, se); // Recover from exception } ## Compliant Solution This compliant solution uses java.util.logging.Logger , the default logging API provided by JDK 1.4 and later. Use of other compliant logging mechanisms, such as log4j, is also permitted. ...
## Risk Assessment Exceptions thrown during data logging can cause loss of data and can conceal security problems. Rule Severity Likelihood Detectable Repairable Priority Level ERR02-J Medium Likely Yes No P12 L1
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 07. Exceptional Behavior (ERR)
java
88,487,753
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487753
2
7
ERR03-J
Restore prior object state on method failure
Objects in general should—and security-critical objects must —be maintained in a consistent state even when exceptional conditions arise. Common techniques for maintaining object consistency include Input validation (on method arguments, for example) Reordering logic so that code that can result in the exceptional cond...
class Dimensions { private int length; private int width; private int height; static public final int PADDING = 2; static public final int MAX_DIMENSION = 10; public Dimensions(int length, int width, int height) { this.length = length; this.width = width; this.height = height; } protected ...
// ... } catch (Throwable t) { MyExceptionReporter mer = new MyExceptionReporter(); mer.report(t); // Sanitize length -= PADDING; width -= PADDING; height -= PADDING; // Revert return -1; } protected int getVolumePackage(int weight) { length += PADDING; width += PADDING; height += PADDING; ...
## Risk Assessment Failure to restore prior object state on method failure can leave the object in an inconsistent state and can violate required state invariants . Rule Severity Likelihood Detectable Repairable Priority Level ERR03-J Low Probable No No P2 L3
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 07. Exceptional Behavior (ERR)
java
88,487,685
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487685
2
7
ERR04-J
Do not complete abruptly from a finally block
Never use return , break , continue , or throw statements within a finally block. When program execution enters a try block that has a finally block, the finally block always executes regardless of whether the try block (or any associated catch blocks) executes to normal completion. Statements that cause the finally bl...
class TryFinally { private static boolean doLogic() { try { throw new IllegalStateException(); } finally { System.out.println("logic done"); return true; } } } ## Noncompliant Code Example ## In this noncompliant code example, thefinallyblock completes abruptly because of areturnstate...
class TryFinally { private static boolean doLogic() { try { throw new IllegalStateException(); } finally { System.out.println("logic done"); } // Any return statements must go here; // applicable only when exception is thrown conditionally } } ## Compliant Solution ## This complian...
## Risk Assessment Abrupt completion of a finally block masks any exceptions thrown inside the associated try and catch blocks. Rule Severity Likelihood Detectable Repairable Priority Level ERR04-J Low Probable Yes Yes P6 L2
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 07. Exceptional Behavior (ERR)
java
88,487,445
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487445
2
7
ERR05-J
Do not let checked exceptions escape from a finally block
Methods invoked from within a finally block can throw an exception. Failure to catch and handle such exceptions results in the abrupt termination of the entire try block. Abrupt termination causes any exception thrown in the try block to be lost, preventing any possible recovery method from handling that specific probl...
public class Operation { public static void doOperation(String some_file) { // ... Code to check or set character encoding ... try { BufferedReader reader = new BufferedReader(new FileReader(some_file)); try { // Do operations } finally { reader.close(); //...
public class Operation { public static void doOperation(String some_file) { // ... Code to check or set character encoding ... try { BufferedReader reader = new BufferedReader(new FileReader(some_file)); try { // Do operations } finally { try { reader.clo...
## Risk Assessment Failure to handle an exception in a finally block may have unexpected results. Rule Severity Likelihood Detectable Repairable Priority Level ERR05-J Low Unlikely Yes No P2 L3
SEI CERT Oracle Coding Standard for Java > 2 Rules > Rule 07. Exceptional Behavior (ERR)
End of preview. Expand in Data Studio

Dataset Card for SEI CERT Oracle Coding Standard for Java (Wiki rules)

Structured export of the SEI CERT Oracle Coding Standard for Java from the SEI wiki.

Dataset Details

Dataset Description

Rows contain Java-specific secure coding rules, guidance text, and examples as published on the CERT Confluence site.

  • Curated by: Derived from public SEI CERT wiki pages; packaged as CSV by the dataset maintainer.
  • Funded by [optional]: [More Information Needed]
  • Shared by [optional]: [More Information Needed]
  • Language(s) (NLP): English (rule text and embedded code).
  • License: Compilation distributed as other; verify with CMU SEI for your use case.

Dataset Sources [optional]

Uses

Direct Use

Java static analysis benchmarks, secure coding curricula, and RAG over CERT Java rules.

Out-of-Scope Use

Does not replace Oracle / SEI official publications or internal policies.

Dataset Structure

All rows share the same columns (scraped from the SEI CERT Confluence wiki):

Column Description
language Language identifier for the rule set
page_id Confluence page id
page_url Canonical wiki URL for the rule page
chapter Chapter label when present
section Section label when present
rule_id Rule identifier (e.g. API00-C, CON50-J)
title Short rule title
intro Normative / explanatory text
noncompliant_code Noncompliant example(s) when present
compliant_solution Compliant example(s) when present
risk_assessment Risk / severity notes when present
breadcrumb Wiki breadcrumb trail when present

Dataset Creation

Curation Rationale

Single-table format for Java CERT rules supports automated ingestion and search.

Source Data

Data Collection and Processing

Scraped from the Java section of the SEI CERT wiki into the shared column layout.

Who are the source data producers?

[More Information Needed]

Annotations [optional]

Annotation process

[More Information Needed]

Who are the annotators?

[More Information Needed]

Personal and Sensitive Information

[More Information Needed]

Bias, Risks, and Limitations

[More Information Needed]

Recommendations

Users should be made aware of the risks, biases and limitations of the dataset. More information needed for further recommendations.

Citation [optional]

BibTeX:

[More Information Needed]

APA:

[More Information Needed]

Glossary [optional]

[More Information Needed]

More Information [optional]

[More Information Needed]

Dataset Card Authors [optional]

[More Information Needed]

Dataset Card Contact

[More Information Needed]

Downloads last month
26