repo stringlengths 1 191 ⌀ | file stringlengths 23 351 | code stringlengths 0 5.32M | file_length int64 0 5.32M | avg_line_length float64 0 2.9k | max_line_length int64 0 288k | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
codeql | codeql-master/java/ql/test/query-tests/security/CWE-327/semmle/tests/Test.java | // Semmle test case for CWE-327: Use of a Broken or Risky Cryptographic Algorithm
// http://cwe.mitre.org/data/definitions/327.html
package test.cwe327.semmle.tests;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
class Test {
public void test() {
try {
String input = "ABCDEFG123456";... | 1,445 | 25.777778 | 81 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-079/semmle/tests/XSS.java | // Test case for
// CWE-079: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
// http://cwe.mitre.org/data/definitions/79.html
package test.cwe079.cwe.examples;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.serv... | 2,145 | 32.015385 | 96 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-732/semmle/tests/Test.java | import java.io.File;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.EnumSet;
import java.util.LinkedHashSet;
import java.util.Se... | 1,159 | 27.292683 | 90 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-022/semmle/tests/Test.java | // Semmle test case for CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
// http://cwe.mitre.org/data/definitions/22.html
package test.cwe22.semmle.tests;
import java.io.IOException;
import java.io.File;
import java.net.InetAddress;
import java.nio.file.Path;
import java.nio.fi... | 1,633 | 21.694444 | 110 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-022/semmle/tests/ZipTest.java | import java.io.*;
import java.nio.file.*;
import java.util.zip.*;
public class ZipTest {
public void m1(ZipEntry entry, File dir) {
String name = entry.getName();
File file = new File(dir, name);
FileOutputStream os = new FileOutputStream(file); // ZipSlip
RandomAccessFile raf = new RandomAccessFile(... | 2,162 | 32.796875 | 71 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-835/semmle/tests/InfiniteLoop.java | class Test {
public void bad() {
for (int i=0; i<10; i++) {
for (int j=0; i<10; j++) {
// potentially infinite loop due to test on wrong variable
if (shouldBreak()) break;
}
}
}
private boolean shouldBreak() {
return Math.random... | 338 | 23.214286 | 74 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-335/semmle/tests/Test.java | // Semmle test case for CWE-335: Use of a predictable seed in a secure random number generator
// http://cwe.mitre.org/data/definitions/335.html
package test.cwe335.semmle.tests;
import java.util.Random;
import java.security.SecureRandom;
import java.math.BigInteger;
class Test {
public void test() {
long time1 = ... | 2,191 | 34.354839 | 95 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-833/semmle/tests/MethodAccessLockOrder.java | class MethodAccessLockOrder {
private Account primary = new Account();
private Account savings = new Account();
class Account {
private int balance;
public synchronized boolean transferFrom(Account malo, int amount) {
int subtracted = malo.subtract(amount);
if (subtracted == amount) {
balance += subtr... | 756 | 20.027778 | 70 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-833/semmle/tests/SynchronizedStmtLockOrder.java | class SynchronizedStmtLockOrder {
private int primaryAccountBalance;
private Object primaryLock = new Object();
private int savingsAccountBalance;
private Object savingsLock = new Object();
public boolean transferToSavings(int amount) {
synchronized(primaryLock) {
synchronized(savingsLock) {
if (amount>0... | 870 | 24.617647 | 60 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-833/semmle/tests/ReentrantLockOrder.java | import java.util.concurrent.locks.ReentrantLock;
class ReentrantLockOrder {
private int primaryAccountBalance;
private final ReentrantLock primaryLock = new ReentrantLock();
private int savingsAccountBalance;
private final ReentrantLock savingsLock = new ReentrantLock();
public boolean transferToSavings(int amou... | 1,047 | 23.952381 | 63 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-611/SAXBuilderTests.java | import java.net.Socket;
import org.jdom.input.SAXBuilder;
public class SAXBuilderTests {
public void unconfiguredSAXBuilder(Socket sock) throws Exception {
SAXBuilder builder = new SAXBuilder();
builder.build(sock.getInputStream()); //unsafe
}
public void safeBuilder(Socket sock) throws Exception {
... | 754 | 31.826087 | 85 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-611/XPathExpressionTests.java | import java.net.Socket;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import org.xml.sax.InputSource;
public class XPathExpressionTests {
public void safeXPathExp... | 1,090 | 35.366667 | 87 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-611/SchemaTests.java | import java.net.Socket;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
public class SchemaTests {
public void unconfiguredSchemaFactory(Socket sock) throws Exception {
SchemaFactory factory = SchemaFa... | 2,281 | 46.541667 | 90 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-611/SAXReaderTests.java | import java.net.Socket;
import org.dom4j.io.SAXReader;
public class SAXReaderTests {
public void unconfiguredReader(Socket sock) throws Exception {
SAXReader reader = new SAXReader();
reader.read(sock.getInputStream()); //unsafe
}
public void safeReader(Socket sock) throws Exception {
SAXReader r... | 2,977 | 45.53125 | 92 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-611/DocumentBuilderTests.java | import java.net.Socket;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.XMLConstants;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import org.xml.sax.InputSource;
class DocumentBuilderTests {
public void unconfi... | 5,986 | 44.015038 | 111 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-611/TransformerTests.java | import java.net.Socket;
import javax.xml.XMLConstants;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.sax.SAXSource;
import org.xml.sax.InputSource;
... | 7,181 | 48.875 | 94 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-611/XMLReaderTests.java |
import java.net.Socket;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.dom4j.io.SAXReader;
public class XMLReaderTests {
public void unconfiguredReader(Socket sock... | 5,177 | 49.271845 | 98 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-611/SimpleXMLTests.java | import java.io.InputStreamReader;
import java.net.Socket;
import org.simpleframework.xml.core.Persister;
import org.simpleframework.xml.stream.DocumentProvider;
import org.simpleframework.xml.stream.NodeBuilder;
import org.simpleframework.xml.stream.StreamProvider;
import org.simpleframework.xml.stream.Formatter;
pub... | 5,353 | 33.320513 | 92 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-611/SAXParserTests.java | import java.net.Socket;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.helpers.DefaultHandler;
public class SAXParserTests {
public void unconfiguredParser(Socket sock) throws Exception {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXPar... | 3,874 | 49.986842 | 96 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-611/XmlInputFactoryTests.java | import java.net.Socket;
import javax.xml.stream.XMLInputFactory;
public class XmlInputFactoryTests {
public void unconfigureFactory(Socket sock) throws Exception {
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.createXMLStreamReader(sock.getInputStream()); //unsafe
factory.createXMLEve... | 2,669 | 44.254237 | 80 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-134/semmle/tests/Test.java | // Test case for
// CWE-134: Use of Externally-Controlled Format String
// http://cwe.mitre.org/data/definitions/134.html
package test.cwe134.cwe.examples;
import java.io.IOException;
import java.util.Formatter;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
im... | 1,524 | 34.465116 | 121 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-807/semmle/tests/Test.java | // Test case for CWE-807 (Reliance on Untrusted Inputs in a Security Decision)
// http://cwe.mitre.org/data/definitions/807.html
package test.cwe807.semmle.tests;
import java.net.InetAddress;
import java.net.Inet4Address;
import java.net.UnknownHostException;
import javax.servlet.http.Cookie;
import org.apache.shi... | 3,425 | 24.954545 | 83 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-601/semmle/tests/UrlRedirect.java | // Test case for
// CWE-601: URL Redirection to Untrusted Site ('Open Redirect')
// http://cwe.mitre.org/data/definitions/601.html
package test.cwe601.cwe.examples;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest... | 1,757 | 34.877551 | 95 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-421/semmle/Test.java | // Test case for CWE-421 (Race Condition During Access to Alternate Channel)
// http://cwe.mitre.org/data/definitions/421.html
package test.cwe807.semmle.tests;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.ByteBuffer;
import ... | 2,198 | 27.192308 | 76 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-129/semmle/tests/Test.java | // Test case for
// CWE-129: Improper Validation of Array Index
// http://cwe.mitre.org/data/definitions/129.html
package test.cwe129.cwe.examples;
import java.security.SecureRandom;
class Test {
public static void basic() {
int array[] = { 0, 1, 2, 3, 4 };
String userProperty = System.getProperty("userPr... | 2,715 | 25.115385 | 93 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-367/semmle/tests/Test.java | // Semmle test case for CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition
// http://cwe.mitre.org/data/definitions/367.html
package test.cwe367.semmle.tests;
class Test {
public final Object lock = new Object();
public volatile boolean aField = true;
public synchronized void bad1(Resource r) {
// pro... | 2,322 | 17.007752 | 82 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-090/LdapInjection.java | import java.util.List;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.ldap.InitialLdapContext;
impo... | 16,253 | 41.328125 | 128 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-113/semmle/tests/ResponseSplitting.java | // Test case for
// CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting')
// http://cwe.mitre.org/data/definitions/113.html
package test.cwe113.cwe.examples;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.ser... | 1,745 | 32.576923 | 97 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-829/semmle/tests/A.java | public class A {
}
| 19 | 5.666667 | 16 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-502/A.java | import java.io.*;
import java.net.Socket;
import java.beans.XMLDecoder;
import com.thoughtworks.xstream.XStream;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.sna... | 3,467 | 34.387755 | 71 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-502/TestMessageBodyReader.java | import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
public class TestMessageBodyReader imple... | 910 | 31.535714 | 109 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-089/semmle/examples/Test.java |
// Test cases for CWE-089 (SQL injection and Java Persistence query injection)
// http://cwe.mitre.org/data/definitions/89.html
package test.cwe089.semmle.tests;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import... | 7,850 | 34.364865 | 91 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-089/semmle/examples/Validation.java | // Test case for CWE-089 (SQL injection)
// http://cwe.mitre.org/data/definitions/89.html
package test.cwe089.semmle.tests;
public class Validation {
public static void checkIdentifier(String id) {
for (int i = 0; i < id.length(); i++) {
char c = id.charAt(i);
if (!Character.isLetter(c)) {
throw new Runti... | 376 | 24.133333 | 60 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-311/CWE-319/Test.java | import java.net.HttpURLConnection;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
class Test {
public void m1(HttpURLConnection connection) {
InputStream input;
if (connection instanceof HttpsURLConnection) {
input = connection.getInputStream(); // OK
} else {
input = connection.g... | 356 | 22.8 | 51 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-311/CWE-614/semmle/tests/Test.java | // Semmle test case for CWE-614: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute
// http://cwe.mitre.org/data/definitions/614.html
package test.cwe614.semmle.tests;
import javax.servlet.http.*;
class Test {
public static void test(HttpServletRequest request, HttpServletResponse response) {
{
Coo... | 604 | 19.862069 | 93 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-798/semmle/tests/Test.java | package test.cwe798.cwe.examples;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Test {
public static void main(String[] args) throws SQLException {
String url = "jdbc:mysql://localhost/test";
String usr = "admin"; // hard-coded user name (flow source)
String pass = "123456"; // hard... | 1,617 | 40.487179 | 107 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-798/semmle/tests/CredentialsTest.java | package test.cwe798.cwe.examples;
import java.sql.DriverManager;
import java.sql.SQLException;
public class CredentialsTest {
private static final String p = "123456"; // hard-coded credential (flow source)
public static void main(String[] args) throws SQLException {
String url = "jdbc:mysql://localhost/test";
... | 636 | 29.333333 | 81 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-798/semmle/tests/FileCredentialTest.java | package test.cwe798.cwe.examples;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.DriverManager;
import java.sql.SQLException;
public class FileCredentialTest {
public static void main(String[] args) throws SQLException, IOException {... | 1,107 | 26.7 | 95 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-798/semmle/tests/HardcodedAWSCredentials.java | import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
public class HardcodedAWSCredentials {
public static void main(String[] args) {
//BAD: Hardcoded credentials for connecting to AWS services
//To fix the problem, use other approaches including AWS credentials file, environmen... | 458 | 44.9 | 142 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-798/semmle/tests/User.java | class User {
private static final String DEFAULT_PW = "123456"; // hard-coded password
private String pw;
public User() {
setPassword(DEFAULT_PW); // sensitive call
}
public void setPassword(String password) {
pw = password;
}
} | 238 | 22.9 | 74 | java |
codeql | codeql-master/java/ql/test/query-tests/security/CWE-209/semmle/tests/Test.java | // Semmle test cases for rule CWE-209: Information Exposure Through an Error Message
// https://cwe.mitre.org/data/definitions/209.html
package test.cwe209.semmle.tests;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.... | 1,884 | 24.133333 | 84 | java |
codeql | codeql-master/java/ql/test/query-tests/SynchSetUnsynchGet/Test.java | class SynchSetUnsynchGet {
private static int var;
public synchronized void setA(int a) {
this.var = a;
}
public synchronized int getA() {
return var; // ok get is synchronized
}
public synchronized void setB(int a) {
this.var = a;
}
public int getB() {
return var; // bad
}
public synchroni... | 950 | 15.396552 | 48 | java |
codeql | codeql-master/java/ql/test/query-tests/InnerClassCouldBeStatic/Test.java | class Test {
static class Super<T> {
public void test() {}
}
class Sub<T> extends Super<T> {
public void test2() {
test();
}
}
}
| 144 | 12.181818 | 33 | java |
codeql | codeql-master/java/ql/test/query-tests/InnerClassCouldBeStatic/Classes.java |
public class Classes {
private static int staticFoo;
protected int foo;
public int bar() { return foo; }
private static int staticBar() { return staticFoo; }
/** Already static. */
private static class Static {
}
/** Could be static. */
private class MaybeStatic {
}
/** Only accesses enclosing... | 5,754 | 20.00365 | 108 | java |
codeql | codeql-master/java/ql/test/query-tests/EqualsUsesInstanceOf/Test.java | import java.util.Comparator;
class Test {
static class CustomComparator<T> implements Comparator<T> {
@Override
public int compare(Object o1, Object o2) {
return 0;
}
}
static class TestComparator extends CustomComparator {
int val;
@Override
public boolean equals(Object o) {
if (o instanceof Te... | 409 | 17.636364 | 60 | java |
codeql | codeql-master/java/ql/test/query-tests/InefficientOutputStream/InefficientOutputStreamGood.java | import java.io.*;
import java.security.*;
import java.util.*;
public class InefficientOutputStreamGood extends OutputStream {
private DigestOutputStream digest;
private byte[] expectedMD5;
public InefficientOutputStreamGood(File file, byte[] expectedMD5) throws IOException, NoSuchAlgorithmException {
this.expe... | 883 | 24.257143 | 113 | java |
codeql | codeql-master/java/ql/test/query-tests/InefficientOutputStream/InefficientOutputStreamBad.java | import java.io.*;
import java.security.*;
import java.util.*;
public class InefficientOutputStreamBad extends OutputStream {
private DigestOutputStream digest;
private byte[] expectedMD5;
public InefficientOutputStreamBad(File file, byte[] expectedMD5) throws IOException, NoSuchAlgorithmException {
this.expect... | 769 | 24.666667 | 112 | java |
codeql | codeql-master/java/ql/test/query-tests/PartiallyMaskedCatch/PartiallyMaskedCatchTest.java | import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class PartiallyMaskedCatchTest {
public static void method() {
try(ClosableThing thing = new ClosableThing()){
thing.doThing();
} catch (ExceptionB e) {
//... | 3,885 | 34.981481 | 116 | java |
codeql | codeql-master/java/ql/test/query-tests/MissingOverrideAnnotation/Test.java | import java.util.Arrays;
import java.util.stream.Collectors;
class Super {
int m() {
return 23;
}
private void n() {}
public String f() {
return "Hello";
}
}
public class Test extends Super {
// NOT OK
int m() {
return 42;
}
// OK
public void n() {}
// OK
@Override
public String f() {
ret... | 446 | 11.771429 | 73 | java |
codeql | codeql-master/java/ql/test/query-tests/WhitespaceContradictsPrecedence/WhitespaceContradictsPrecedence.java | public class WhitespaceContradictsPrecedence {
int bad(int x) {
return x + x>>1;
}
int ok1(int x) {
return x + x >> 1;
}
int ok2(int x) {
return x+x >> 1;
}
int ok3(int x) {
return x + (x>>1);
}
int ok4(int x, int y, int z) {
return x + y + z;
}
int ok5(int x, int y, int z) {
return x +... | 373 | 11.896552 | 46 | java |
codeql | codeql-master/java/ql/test/query-tests/UselessNullCheck/A.java | public class A {
void f() {
Object o = new Object();
if (o == null) { } // Useless check
if (o != null) { } // Useless check
try {
new Object();
} catch(Exception e) {
if (e == null) { // Useless check
throw new Exception();
}
}
}
void g(Object o) {
if (o ins... | 998 | 16.526316 | 57 | java |
codeql | codeql-master/java/ql/test/query-tests/SelfAssignment/Test.java | class Outer {
int x;
Outer(int x) {
// NOT OK
x = x;
// OK
this.x = x;
}
Outer() {}
class Inner {
int x;
// OK
{ x = Outer.this.x; }
}
class Inner2 extends Outer {
// OK
{ x = Outer.this.x; }
}
} | 225 | 8.826087 | 29 | java |
codeql | codeql-master/java/ql/test/query-tests/LazyInitStaticField/LazyInits.java | public class LazyInits {
private static Object lock = new Object();
private static Object badLock;
public void resetLock() {
badLock = new Object();
}
// Eager init
public static final LazyInits eager = new LazyInits();
// Correct lazy inits
public static LazyInits correct1;
public synchronized static ... | 3,659 | 19.677966 | 113 | java |
codeql | codeql-master/java/ql/test/query-tests/UseBraces/UseBraces.java |
class UseBraces
{
void f() { }
void g() { }
void h() { }
void test()
{
int x, y;
int[] branches = new int[10];
// If-then statement
if(1==1)
{
f();
}
g(); // No alert
if(1==1)
f();
g(); // No alert
if(1==1)
f();
g(); // Alert
if(1==1)
f(); g(); // Alert
... | 2,062 | 9.366834 | 31 | java |
codeql | codeql-master/java/ql/test/query-tests/MissedTernaryOpportunity/MissedTernaryOpportunityTest.java | import java.util.*;
public class MissedTernaryOpportunityTest {
public static boolean missedOpportunity1(int a){
if(a == 42)
return true;
else
return false;
}
public static boolean doNotComplain1(int a){
if(a == 42){
return true;
}else{
System.out.println("output");
return false;
}
}
... | 3,602 | 19.82659 | 74 | java |
codeql | codeql-master/java/ql/test/query-tests/AvoidDeprecatedCallableAccess/Test.java | public class Test {
@Deprecated
void m() {}
@Deprecated
void n() {
// OK
m();
}
{
// NOT OK
m();
}
public static void main(String[] args) {
// NOT OK
new Test().n();
}
} | 196 | 8.85 | 41 | java |
codeql | codeql-master/java/ql/test/query-tests/ReturnValueIgnored/return_value_ignored/Test.java | package return_value_ignored;
interface I {
I setI(int i);
}
public class Test implements I {
private int i;
public Test(int i) {
this.i = i;
}
public int getI() {
return i;
}
public Test setI(int i) {
this.i = i;
return this;
}
public static void main(String[] args) {
Test test1 = new Test... | 1,629 | 16.717391 | 42 | java |
codeql | codeql-master/java/ql/test/query-tests/MissingInstanceofInEquals/AlsoGood.java | class AlsoGood {
private int data;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + data;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
return checkEquality(this, ob... | 1,244 | 17.863636 | 66 | java |
codeql | codeql-master/java/ql/test/query-tests/MissingInstanceofInEquals/Bad.java | class Bad {
private int data;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + data;
return result;
}
@Override
public boolean equals(Object obj) {
Bad other = (Bad) obj;
if (data != other.data)
return false;
return true;
}
} | 300 | 14.842105 | 36 | java |
codeql | codeql-master/java/ql/test/query-tests/MissingInstanceofInEquals/GoodReturn.java | class GoodReturn {
public static final GoodReturn GR = new GoodReturn();
@Override
public int hashCode() {
getClass().hashCode();
}
@Override
public boolean equals(Object obj) {
return obj == GR;
}
}
| 224 | 15.071429 | 55 | java |
codeql | codeql-master/java/ql/test/query-tests/MissingInstanceofInEquals/Good.java | class Good {
private int data;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + data;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())... | 427 | 16.12 | 36 | java |
codeql | codeql-master/java/ql/test/query-tests/IteratorRemoveMayFail/Test.java | import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class Test {
public static void main(String[] args) {
A a = A.mkA(23, 42);
Iterator<Integer> iter = a.getL().iterator();
removeOdd(iter);
}
private static void removeOdd(Iterator<Integer> iter) {
... | 696 | 16.871795 | 56 | java |
codeql | codeql-master/java/ql/test/query-tests/ContradictoryTypeChecks/Test.java | public class Test<T> {
static class Super {}
static class Sub1 extends Super {}
static class Sub2 extends Super {}
// modeled after results on Alfresco
void foo(Super lhs, Super rhs) {
if (lhs instanceof Sub1) ;
else if (rhs instanceof Sub1)
if ((lhs instanceof Sub1) || (lhs instanceof Sub2));
}
void ba... | 1,265 | 19.095238 | 72 | java |
codeql | codeql-master/java/ql/test/query-tests/NotifyWithoutSynch/Test.java | class NotifyWithoutSynch {
private Object obj1;
private Object obj2;
public synchronized void pass_unqualified_wait() throws InterruptedException {
wait();
}
public void fail_unqualified_wait() throws InterruptedException {
wait();
}
public synchronized void pass_unqualified_notify() throws InterruptedExc... | 2,651 | 20.917355 | 84 | java |
codeql | codeql-master/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.java | import java.lang.InterruptedException;
import java.lang.Exception;
import java.lang.RuntimeException;
class ImpossibleJavadocThrows {
/**
*
* @throws InterruptedException
*/
public void bad1() {
}
/**
*
* @exception Exception
*/
public void bad2() {
}
/**
*
* @throws InterruptedExceptio... | 459 | 12.529412 | 45 | java |
codeql | codeql-master/java/ql/test/query-tests/MutualDependency/otherpackage/OtherClass.java | package otherpackage;
public class OtherClass {
public static int c = onepackage.MutualDependency.B.b;
}
| 107 | 17 | 55 | java |
codeql | codeql-master/java/ql/test/query-tests/MutualDependency/onepackage/MutualDependency.java | package onepackage;
public class MutualDependency {
static int m = A.a;
// allow intra-package dependencies
static class A {
static int a = m;
}
// disallow inter-package dependencies
public static class B {
public static int b = otherpackage.OtherClass.c;
}
}
| 273 | 18.571429 | 50 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadMethod/SuppressedConstructorTest.java | public class SuppressedConstructorTest {
private static class SuppressedConstructor {
// This should not be reported as dead
private SuppressedConstructor() { }
public static void liveMethod() { }
}
public void deadMethod() {
new NestedPrivateConstructor();
}
private static class NestedPriv... | 1,057 | 26.842105 | 99 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadMethod/InternalDeadCodeCycle.java | public class InternalDeadCodeCycle {
public void foo() {
bar();
}
public void bar() {
foo();
}
public static void main(String[] args) {
// Ensure the class is live, otherwise the dead methods will not be reported.
}
}
| 233 | 14.6 | 79 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadMethod/ReflectionMethodTest.java | public class ReflectionMethodTest {
public static class TestObject1 {
public void test1() { }
}
public static class TestObject2 {
public void test2() { }
}
public static class TestObject3 {
public void test3() { }
}
public static class TestObject4 {
public void test4() { }
}
public... | 1,259 | 29 | 120 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadMethod/JMXTest.java | import java.lang.management.ManagementFactory;
import javax.management.ObjectName;
public class JMXTest {
public static interface FooMBean {
public String sometimesLiveMethod(String arg);
public String liveMethod2(String arg);
}
public static class FooIntermediate implements FooMBean {
// This method is de... | 1,050 | 30.848485 | 93 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadMethod/ArbitraryXMLLiveness.java | public class ArbitraryXMLLiveness {
public ArbitraryXMLLiveness() {
}
public static void main(String[] args) {
// Ensure the class is live, otherwise the dead methods will not be reported.
}
}
| 201 | 19.2 | 79 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadMethod/DefaultConstructorTest.java | public class DefaultConstructorTest {
}
| 40 | 12.666667 | 37 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadMethod/ReflectionTest.java | public class ReflectionTest {
public static class TestObject1 {
public TestObject1() { }
}
public static class TestObject2 {
public TestObject2() { }
}
public static class TestObject3 {
public TestObject3() { }
}
public static class TestObject4 {
public TestObject4() { }
}
public static class TestO... | 1,187 | 27.285714 | 119 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadClass/NamespaceTest.java | public class NamespaceTest {
/**
* A namespace class because it only includes static members. It should
* be live, because it has a live inner class.
*/
public static class NamespaceClass {
/**
* Empty constructor provided to suppress the default public constructor. Should not prevent this
* ... | 1,370 | 25.365385 | 101 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadClass/InternalDeadCodeCycle.java | /**
* This class should be marked as entirely unused.
*/
public class InternalDeadCodeCycle {
public void foo() {
bar();
}
public void bar() {
foo();
}
}
| 166 | 10.928571 | 50 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadClass/ExternalDeadRoot.java |
public class ExternalDeadRoot {
/**
* This class should be marked as only being used by the "outerDeadRoot()". The
* "innerDeadRoot()" should not be reported as a dead root, as it is internal to the class.
*/
public static class DeadClass {
public static void innerDeadRoot() {
}
public static void inne... | 492 | 19.541667 | 92 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadClass/DeadEnumTest.java | public class DeadEnumTest {
public enum DeadEnum {
A
}
public enum LiveEnum {
A
}
public static void main(String[] args) {
LiveEnum.values();
}
}
| 172 | 11.357143 | 42 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadClass/AnnotationTest.java | import java.lang.SuppressWarnings;
public class AnnotationTest {
@SuppressWarnings("unchecked")
public static class AnnotatedClass {
}
public static void main(String[] args) {
AnnotatedClass.class.getAnnotation(SuppressWarnings.class);
}
}
| 256 | 20.416667 | 63 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadClass/ExternalDeadCodeCycle.java |
public class ExternalDeadCodeCycle {
/**
* This class should be marked as being only used from a dead code cycle, because the dead-code
* cycle is external to the class.
*/
public static class DeadClass {
public static void deadMethod() {
}
}
public static void cyclicDeadMethodA() {
DeadClass.deadMet... | 498 | 18.192308 | 96 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/UselessParameter/Test.java |
interface I {
// NOT OK: no overriding method uses x
void foo(int x);
// OK: no concrete implementation
void bar(String y);
// OK: no concrete implementation
void baz(float f);
// OK: some overriding method uses x
int qux(boolean b);
}
abstract class A implements I {
// OK: I.foo is already flagged
... | 2,594 | 21.763158 | 82 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadField/AnnotationValueTest.java | public class AnnotationValueTest {
public static @interface TestAnnotation {
public String[] value();
}
@TestAnnotation(value = AnnotationValueUtil.LIVE_STRING_CONSTANT_FIELD)
public static String liveField = "";
@TestAnnotation(value = AnnotationValueUtil.DEAD_STRING_CONSTANT_FIELD)
public static String dea... | 1,264 | 27.75 | 94 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadField/BasicTest.java | public class BasicTest {
private static String deadStaticField = "Dead";
private static String liveStaticField = "Live";
private String deadField;
private String deadCycleField;
private String liveField;
public BasicTest(String deadField, String liveField) {
this.deadField = deadField;
this.liveField = liveF... | 887 | 20.142857 | 55 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadField/AnnotationValueUtil.java |
public class AnnotationValueUtil {
/**
* Live because it is used as an annotation value on a live field.
*/
public static final String LIVE_STRING_CONSTANT_FIELD = "A string constant.";
/**
* Live because it is used as annotation values on a live method.
*/
public static final String LIVE_STRING_CONSTAN... | 944 | 30.5 | 105 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadField/ReflectionTest.java | public class ReflectionTest {
public static class ParentClass {
// Not live
private int notInheritedField;
// Live because it is accessed through ChildClass
public int inheritedField;
// Not live because it is shadowed by the child
public int shadowedField;
}
public static class ChildClass extends Pare... | 780 | 25.931034 | 74 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadEnumConstant/DeadEnumConstantTest.java | import java.util.*;
public class DeadEnumConstantTest {
public @interface MyAnnotation{};
public static enum E1{
unused1,
unused2,
@MyAnnotation
ok1, // constants with reflective annotations should be ignored
ok2, ok3, ok4, ok5,
}
@MyAnnotation
public... | 874 | 24 | 107 | java |
codeql | codeql-master/java/ql/test/query-tests/dead-code/DeadCallable/Main.java | public class Main {
private static String ss = "a";
private static String ss2 = "b";
private final String is = "a";
private final String is2 = "b";
private void unused() {
indirectlyUnused();
}
private void indirectlyUnused() {}
private void foo() { bar(); }
private void bar() { foo(); }
public static... | 351 | 18.555556 | 42 | java |
codeql | codeql-master/java/ql/test/query-tests/RangeAnalysis/A.java | public class A {
private static final int[] arr1 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
private final int[] arr2;
private final int[] arr3;
public A(int[] arr2, int n) {
if (arr2.length % 2 != 0)
throw new Exception();
this.arr2 = arr2;
this.arr3 = new int[n << 1];
}
void m1(int[] a) {
... | 4,152 | 19.974747 | 73 | java |
codeql | codeql-master/java/ql/test/query-tests/Finally/Finally.java |
class InFinally {
void returnVoidInFinally() {
try {
} finally {
return;
}
}
int returnIntInFinally(boolean b1, boolean b2) {
try {
if (b1) {
return 4;
}
} finally {
if (b2) {
return 5;
}
}
return 3;
}
int throwInFinally(boolean b1, boolean b2) {
try {
if (b1) {
thr... | 1,619 | 11.180451 | 49 | java |
codeql | codeql-master/java/ql/test/query-tests/Declarations/Test.java |
public class Test {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
switch(args.length) {
case -2:
return;
case -1:
continue;
case 0:
System.out.println("No args");
break;
case 1:
case 2:
System.out.println("1-2 args");
// missing break.
... | 601 | 17.8125 | 41 | java |
codeql | codeql-master/java/ql/test/query-tests/SpuriousJavadocParam/Test.java | public class Test<V> {
// no javadoc
public void ok0(){ }
/* no javadoc */
public void ok1(){ }
/**
* no tags
*/
public void ok2(){ }
/**
* @param p1 correctly spelled
*/
public void ok3(int p1){ }
/**
* @param <T> type parameter
*/
public <T> T ok4(){ return null; }
/**
... | 1,852 | 16 | 49 | java |
codeql | codeql-master/java/ql/test/query-tests/ReadOnlyContainer/Test.java | import java.util.*;
public class Test {
boolean containsDuplicates(Object[] array) {
Set<Object> seen = new HashSet<Object>();
for (Object o : array) {
// should be flagged
if (seen.contains(o))
return true;
}
return false;
}
void foo(List<Integer> l) {
// should not be flagged
l.contains(23... | 1,531 | 17.238095 | 65 | java |
codeql | codeql-master/java/ql/test/query-tests/StaticArray/StaticArray.java | class StaticArray
{
public static final int[] bad = new int[42]; //NOT OK
protected static final int[] good_protected = new int[42]; //OK (protected arrays are ok)
/* default */ static final int[] good_default = new int[42]; //OK (default access arrays are ok)
private static final int[] good_private = ... | 1,302 | 43.931034 | 100 | java |
codeql | codeql-master/java/ql/test/query-tests/Iterable/Test.java | import java.util.*;
class Test {
void useIterable(Iterable<String> i) {
for (String s : i) { }
for (String s : i) { }
}
List<String> someStrings;
void m() {
useIterable(new Iterable<String>() {
final Iterator<String> i = someStrings.iterator(); // bad
@Override
public Ite... | 4,306 | 22.535519 | 78 | java |
codeql | codeql-master/java/ql/test/query-tests/SuspiciousDateFormat/A.java | import java.text.SimpleDateFormat;
import java.util.Date;
public class A {
public static void main(String[] args) {
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(new Date())); // OK
System.out.println(new SimpleDateFormat("YYYY-ww").format(new Date())); // OK
System.out.println(new SimpleDateForm... | 370 | 32.727273 | 83 | java |
codeql | codeql-master/java/ql/test/query-tests/LShiftLargerThanTypeWidth/A.java | public class A {
void test1(byte b, char c, short s, int i, long l) {
long b1 = b << 31; // OK
long b2 = b << 32; // BAD
long b3 = b << 33; // BAD
long b4 = b << 64; // BAD
long c1 = c << 22; // OK
long c2 = c << 42; // BAD
long s1 = s << 22; // OK
long s2 = s << 42; // BAD
long... | 1,221 | 22.5 | 63 | java |
codeql | codeql-master/java/ql/test/query-tests/HashedButNoHash/Test.java | import java.util.HashMap;
import java.util.IdentityHashMap;
class Test {
{
IdentityHashMap<Object, String> map = new IdentityHashMap<>();
A a = new A();
map.put(a, "value");
HashMap<Object, String> map2 = new HashMap<>();
map2.put(a, "value");
}
}
class A {
int i;
@Override
public boolean equals(Object... | 546 | 14.628571 | 64 | java |
codeql | codeql-master/java/ql/test/query-tests/AlertSuppression/TestSuppressWarnings.java |
@SuppressWarnings("lgtm[java/non-sync-override]")
@Deprecated
class TestSuppressWarnings {
@SuppressWarnings("lgtm[]")
public void test() {
}
@Deprecated
@SuppressWarnings({"lgtm[java/confusing-method-name] not confusing","lgtm[java/non-sync-override]"})
public void test2() {
... | 539 | 22.478261 | 104 | java |
codeql | codeql-master/java/ql/test/query-tests/AlertSuppression/Test.java | class Test {} // lgtm
// lgtm[java/confusing-method-name]
// lgtm[java/confusing-method-name, java/non-short-circuit-evaluation]
// lgtm[@tag:exceptions]
// lgtm[@tag:exceptions,java/confusing-method-name]
// lgtm[@expires:2017-06-11]
// lgtm[java/confusing-method-name] does not seem confusing despite alert by lgtm
// ... | 1,039 | 25.666667 | 81 | java |
codeql | codeql-master/java/ql/test/query-tests/AlertSuppression/TestWindows.java | class TestWindows {} // lgtm
// lgtm[java/confusing-method-name]
// lgtm[java/confusing-method-name, java/non-short-circuit-evaluation]
// lgtm[@tag:exceptions]
// lgtm[@tag:exceptions,java/confusing-method-name]
// lgtm[@expires:2017-06-11]
// lgtm[java/confusing-method-name] does not seem confusing despite alert by l... | 1,046 | 25.846154 | 81 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.