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/javascript/extractor/src/com/semmle/js/extractor/ScriptExtractor.java
package com.semmle.js.extractor; import com.semmle.js.extractor.ExtractorConfig.Platform; import com.semmle.js.extractor.ExtractorConfig.SourceType; import com.semmle.js.parser.ParseError; import com.semmle.util.data.Pair; import com.semmle.util.trap.TrapWriter.Label; /** Extract a stand-alone JavaScript script. */ p...
2,537
33.767123
92
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/Main.java
package com.semmle.js.extractor; import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; import c...
23,375
39.234079
146
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/RegExpExtractor.java
package com.semmle.js.extractor; import com.semmle.js.ast.Node; import com.semmle.js.ast.Position; import com.semmle.js.ast.SourceElement; import com.semmle.js.ast.regexp.BackReference; import com.semmle.js.ast.regexp.Caret; import com.semmle.js.ast.regexp.CharacterClass; import com.semmle.js.ast.regexp.CharacterClass...
11,281
29.409704
95
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/JSExtractor.java
package com.semmle.js.extractor; import com.semmle.js.ast.Comment; import com.semmle.js.ast.Node; import com.semmle.js.ast.Token; import com.semmle.js.extractor.ExtractionMetrics.ExtractionPhase; import com.semmle.js.extractor.ExtractorConfig.ECMAVersion; import com.semmle.js.extractor.ExtractorConfig.Platform; import...
6,578
41.445161
101
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/JSDocExtractor.java
package com.semmle.js.extractor; import com.semmle.js.ast.Comment; import com.semmle.js.ast.jsdoc.AllLiteral; import com.semmle.js.ast.jsdoc.ArrayType; import com.semmle.js.ast.jsdoc.FieldType; import com.semmle.js.ast.jsdoc.FunctionType; import com.semmle.js.ast.jsdoc.JSDocComment; import com.semmle.js.ast.jsdoc.JSDo...
7,602
29.170635
96
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/NodeJSDetector.java
package com.semmle.js.extractor; import com.semmle.js.ast.AssignmentExpression; import com.semmle.js.ast.BlockStatement; import com.semmle.js.ast.CallExpression; import com.semmle.js.ast.Expression; import com.semmle.js.ast.ExpressionStatement; import com.semmle.js.ast.IFunction; import com.semmle.js.ast.Identifier; i...
6,154
34.784884
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/LexicalExtractor.java
package com.semmle.js.extractor; import com.semmle.js.ast.Comment; import com.semmle.js.ast.Position; import com.semmle.js.ast.SourceElement; import com.semmle.js.ast.Token; import com.semmle.js.extractor.ExtractionMetrics.ExtractionPhase; import com.semmle.util.trap.TrapWriter; import com.semmle.util.trap.TrapWriter....
6,994
31.087156
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/ExtractorState.java
package com.semmle.js.extractor; import java.nio.file.Path; import java.util.concurrent.ConcurrentHashMap; import com.semmle.js.parser.TypeScriptParser; /** * Contains the state to be shared between extractions of different files. * * <p>In general, this contains both semantic state that affects the extractor out...
1,552
31.354167
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/ExprKinds.java
package com.semmle.js.extractor; import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.Map; import com.semmle.jcorn.TokenType; import com.semmle.jcorn.jsx.JSXParser; import com.semmle.js.ast.AssignmentExpression; import com.semmle.js.ast.BinaryExpression; import com.semmle.js.ast.ComprehensionBlo...
10,576
33.119355
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java
package com.semmle.js.extractor; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; import java.util.Stack; import com.semmle.js.ast.AClass; import com.semmle.js.ast.AFunction; import com.semmle.js.ast.AFunctionExpression; import com.semmle.js.ast.ArrayExpression; i...
74,504
34.143868
117
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/DeclaredNames.java
package com.semmle.js.extractor; import java.util.LinkedHashSet; import java.util.Set; /** Names of variables, types, and namespaces declared in a particular scope. */ public class DeclaredNames { private Set<String> variableNames; private Set<String> typeNames; private Set<String> namespaceNames; public Dec...
1,063
24.95122
86
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/VirtualSourceRoot.java
package com.semmle.js.extractor; import java.nio.file.Path; public class VirtualSourceRoot { private Path sourceRoot; private Path virtualSourceRoot; private Object lock = new Object(); public static final VirtualSourceRoot none = new VirtualSourceRoot(null, null); public VirtualSourceRoot(Path sourceRoot...
2,550
30.493827
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/HTMLExtractor.java
package com.semmle.js.extractor; import java.io.File; import java.nio.file.Path; import java.util.regex.Pattern; import com.semmle.js.extractor.ExtractorConfig.Platform; import com.semmle.js.extractor.ExtractorConfig.SourceType; import com.semmle.js.parser.ParseError; import com.semmle.util.data.StringUtil; import co...
16,247
37.051522
147
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/ExtractionMetrics.java
package com.semmle.js.extractor; import com.semmle.util.trap.TrapWriter; import com.semmle.util.trap.TrapWriter.Label; import java.io.File; import java.lang.management.ManagementFactory; import java.lang.management.ThreadMXBean; import java.util.Stack; /** Metrics for the (single-threaded) extraction of a single file...
5,256
30.291667
106
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/LocationManager.java
package com.semmle.js.extractor; import com.semmle.js.ast.Position; import com.semmle.js.ast.SourceElement; import com.semmle.util.files.FileUtil; import com.semmle.util.trap.TrapWriter; import com.semmle.util.trap.TrapWriter.Label; import java.io.File; import java.util.LinkedHashSet; import java.util.Set; /** * Thi...
4,648
31.971631
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/ScopeManager.java
package com.semmle.js.extractor; import com.semmle.js.ast.ArrayPattern; import com.semmle.js.ast.BlockStatement; import com.semmle.js.ast.CatchClause; import com.semmle.js.ast.ClassBody; import com.semmle.js.ast.ClassDeclaration; import com.semmle.js.ast.DefaultVisitor; import com.semmle.js.ast.DoWhileStatement; impor...
22,816
31.972543
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/OffsetTranslation.java
package com.semmle.js.extractor; import com.semmle.util.data.IntList; /** * A mapping of some source range into a set of intervals in an output source range. * * <p>The mapping is constructed by adding "anchors": input/output pairs that correspond to the * beginning of an interval, which is assumed to end at the ...
1,142
27.575
95
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/LoCInfo.java
package com.semmle.js.extractor; /** * Utility class for representing LoC information; really just a glorified <code> * Pair&lt;Integer, Integer&gt;</code>. */ public class LoCInfo { private int linesOfCode, linesOfComments; public LoCInfo(int linesOfCode, int linesOfComments) { this.linesOfCode = linesOfC...
636
21.75
81
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/TypeExprKinds.java
package com.semmle.js.extractor; import com.semmle.jcorn.TokenType; import com.semmle.js.ast.DefaultVisitor; import com.semmle.js.ast.INode; import com.semmle.js.ast.Identifier; import com.semmle.js.ast.Literal; import com.semmle.js.ast.MemberExpression; import com.semmle.js.extractor.ASTExtractor.IdContext; import co...
9,516
36.916335
97
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/EnvironmentVariables.java
package com.semmle.js.extractor; import com.semmle.util.exception.UserError; import com.semmle.util.process.Env; import com.semmle.util.process.Env.Var; public class EnvironmentVariables { public static final String CODEQL_EXTRACTOR_JAVASCRIPT_ROOT_ENV_VAR = "CODEQL_EXTRACTOR_JAVASCRIPT_ROOT"; public stat...
1,901
34.886792
124
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/DependencyInstallationResult.java
package com.semmle.js.extractor; import java.nio.file.Path; import java.util.Collections; import java.util.Map; /** Contains the results of installing dependencies. */ public class DependencyInstallationResult { private Map<String, Path> packageEntryPoints; private Map<String, Path> packageJsonFiles; public st...
1,071
27.972973
87
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/JSONExtractor.java
package com.semmle.js.extractor; import com.semmle.js.ast.json.JSONArray; import com.semmle.js.ast.json.JSONLiteral; import com.semmle.js.ast.json.JSONObject; import com.semmle.js.ast.json.JSONValue; import com.semmle.js.ast.json.Visitor; import com.semmle.js.parser.JSONParser; import com.semmle.js.parser.ParseError; ...
4,098
35.598214
96
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/TypeScriptMode.java
package com.semmle.js.extractor; /** The amount of information to extract from TypeScript files. */ public enum TypeScriptMode { /** TypeScript files will not be extracted. */ NONE, /** * Only syntactic information will be extracted from TypeScript files. * * <p>This requires Node.js and the TypeScript...
483
24.473684
97
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/TextualExtractor.java
package com.semmle.js.extractor; import java.io.File; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.semmle.js.ast.Position; import com.semmle.js.ast.SourceElement; import com.semmle.util.trap.TrapWriter; import com.semmle.util.trap.TrapWriter.Label; /** * Extractor for populating purely...
5,119
29.117647
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java
package com.semmle.js.extractor; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.io.Writer; import java.lang.ProcessBuilder.Redirect; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Sta...
52,090
40.14613
140
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/SyntacticContextManager.java
package com.semmle.js.extractor; import com.semmle.js.ast.BreakStatement; import com.semmle.js.ast.JumpStatement; import com.semmle.js.ast.LabeledStatement; import com.semmle.js.ast.Loop; import com.semmle.js.ast.Node; import com.semmle.js.ast.Statement; import com.semmle.js.ast.SwitchStatement; import com.semmle.util...
4,638
32.135714
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/FileSnippet.java
package com.semmle.js.extractor; import java.nio.file.Path; import com.semmle.js.extractor.ExtractorConfig.SourceType; /** * Denotes where a code snippet originated from within a file. */ public class FileSnippet { private Path originalFile; private int line; private int column; private int topLevelKind; ...
913
19.311111
104
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/JumpType.java
package com.semmle.js.extractor; /** Simple enum for representing the four kinds of unstructured control flow in JavaScript. */ public enum JumpType { BREAK, CONTINUE, THROW, RETURN; }
194
18.5
94
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/TypeScriptExtractor.java
package com.semmle.js.extractor; import java.io.File; import com.semmle.js.extractor.ExtractorConfig.ECMAVersion; import com.semmle.js.extractor.ExtractorConfig.SourceType; import com.semmle.js.parser.JSParser.Result; import com.semmle.js.parser.ParseError; public class TypeScriptExtractor implements IExtractor { ...
1,563
40.157895
121
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/CFGExtractor.java
package com.semmle.js.extractor; import com.semmle.js.ast.AClass; import com.semmle.js.ast.AFunctionExpression; import com.semmle.js.ast.ArrayExpression; import com.semmle.js.ast.ArrayPattern; import com.semmle.js.ast.AssignmentExpression; import com.semmle.js.ast.AwaitExpression; import com.semmle.js.ast.BinaryExpres...
67,647
33.408952
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java
package com.semmle.js.extractor; import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; import java.util.S...
14,054
26.612967
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/StmtKinds.java
package com.semmle.js.extractor; import com.semmle.js.ast.DefaultVisitor; import com.semmle.js.ast.ForInStatement; import com.semmle.js.ast.Statement; import com.semmle.js.ast.VariableDeclaration; import com.semmle.util.exception.CatastrophicError; import java.util.LinkedHashMap; import java.util.Map; /** Map from Sp...
3,160
35.333333
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/IExtractor.java
package com.semmle.js.extractor; import java.io.IOException; /** Generic extractor interface. */ public interface IExtractor { /** * Extract a snippet of code whose textual information is provided by the given {@link * TextualExtractor}, and return information about the number of lines of code and the number ...
445
30.857143
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/FileExtractor.java
package com.semmle.js.extractor; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.LinkedHashSet; import java.u...
20,434
36.564338
112
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/JSXTests.java
package com.semmle.js.extractor.test; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.semmle.jcorn.SyntaxError; import com.semmle.jcorn.jsx.JSXOptions; import com.semmle.jcorn.jsx.JSXParser; import com.semmle.js.ast.AST2JSON; import com.semmle.js.ast...
3,470
35.15625
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/ClassPropertiesTests.java
package com.semmle.js.extractor.test; import org.junit.Test; /** * Tests for parsing class properties. * * <p>Most tests are automatically derived from the Babylon test suite as described in <code> * parser-tests/babylon/README.md</code>. */ public class ClassPropertiesTests extends ASTMatchingTests { @Test ...
1,023
20.787234
93
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/ASTMatchingTests.java
package com.semmle.js.extractor.test; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import com.semmle.jcorn.ESNextParser; import com.semmle.jcorn.Options;...
3,525
39.068182
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/NumericSeparatorTests.java
package com.semmle.js.extractor.test; import static org.junit.Assert.*; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import com.semmle.jcorn.ESNextParser; import com.semmle.jcorn.Options; import com.semmle.jcorn.SyntaxError; import com.semmle.js.ast.ExpressionStatement; import...
1,362
29.288889
88
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/TrapTests.java
package com.semmle.js.extractor.test; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import com.semmle.js.extractor.ExtractorState; import com.semmle.js.extractor.Main; import com.semmle.u...
7,236
36.304124
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/FunctionSentTests.java
package com.semmle.js.extractor.test; import org.junit.Test; /** * Tests for parsing <code>function.sent</code>. * * <p>Most tests are automatically derived from the Babylon test suite as described in <code> * parser-tests/babylon/README.md</code>. */ public class FunctionSentTests extends ASTMatchingTests { @...
661
23.518519
93
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/ObjectRestSpreadTests.java
package com.semmle.js.extractor.test; import com.semmle.jcorn.CustomParser; import com.semmle.jcorn.Options; import com.semmle.jcorn.SyntaxError; import org.junit.Assert; import org.junit.Test; /** * Tests for parsing rest/spread properties. * * <p>Most tests are automatically derived from the Babylon test suite a...
1,396
22.283333
93
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/AutoBuildTests.java
package com.semmle.js.extractor.test; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes...
21,668
34.406863
105
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/ExportExtensionsTests.java
package com.semmle.js.extractor.test; import com.semmle.jcorn.Options; import org.junit.Test; /** * Tests for parsing export extensions. * * <p>Most tests are automatically derived from the Babylon test suite as described in <code> * parser-tests/babylon/README.md</code>. */ public class ExportExtensionsTests ex...
917
20.348837
93
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/DecoratorTests.java
package com.semmle.js.extractor.test; import org.junit.Test; /** * Tests for parsing decorators. * * <p>Most tests are automatically derived from the Babylon test suite as described in <code> * parser-tests/babylon/README.md</code>. */ public class DecoratorTests extends ASTMatchingTests { @Test public void ...
1,355
17.833333
93
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/RobustnessTests.java
package com.semmle.js.extractor.test; import com.semmle.jcorn.Options; import com.semmle.jcorn.Parser; import com.semmle.util.io.WholeIO; import java.io.File; import java.nio.charset.StandardCharsets; import org.junit.Test; public class RobustnessTests { @Test public void letLookheadTest() { File test = new ...
500
25.368421
77
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/OffsetTranslationTest.java
package com.semmle.js.extractor.test; import com.semmle.js.extractor.OffsetTranslation; import org.junit.Assert; import org.junit.Test; public class OffsetTranslationTest { @Test public void testBasic() { OffsetTranslation table = new OffsetTranslation(); table.set(0, 10); table.set(100, 250); Ass...
1,406
26.588235
54
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/AllTests.java
package com.semmle.js.extractor.test; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({ JSXTests.class, NodeJSDetectorTests.class, TrapTests.class, ObjectRestSpreadTests.class, ClassPropertiesTests.class, Fun...
504
21.954545
44
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/test/NodeJSDetectorTests.java
package com.semmle.js.extractor.test; import com.semmle.js.ast.Node; import com.semmle.js.extractor.ExtractionMetrics; import com.semmle.js.extractor.ExtractorConfig; import com.semmle.js.extractor.ExtractorConfig.SourceType; import com.semmle.js.extractor.NodeJSDetector; import com.semmle.js.parser.JSParser; import c...
5,220
23.283721
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/trapcache/ITrapCache.java
package com.semmle.js.extractor.trapcache; import com.semmle.js.extractor.ExtractorConfig; import com.semmle.js.extractor.FileExtractor; import java.io.File; /** Generic TRAP cache interface. */ public interface ITrapCache { /** * Look up a file in the TRAP cache. * * @param source the content of the file ...
867
38.454545
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/trapcache/DummyTrapCache.java
package com.semmle.js.extractor.trapcache; import com.semmle.js.extractor.ExtractorConfig; import com.semmle.js.extractor.FileExtractor.FileType; import java.io.File; /** A dummy TRAP cache that does not cache anything. */ public class DummyTrapCache implements ITrapCache { @Override public File lookup(String sou...
389
26.857143
76
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/trapcache/DefaultTrapCache.java
package com.semmle.js.extractor.trapcache; import com.semmle.js.extractor.ExtractorConfig; import com.semmle.js.extractor.FileExtractor.FileType; import com.semmle.util.data.Pair; import com.semmle.util.data.StringDigestor; import com.semmle.util.data.UnitParser; import com.semmle.util.exception.Exceptions; import com...
5,473
37.822695
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/extractor/trapcache/CachingTrapWriter.java
package com.semmle.js.extractor.trapcache; import com.semmle.util.exception.Exceptions; import com.semmle.util.files.FileUtil; import com.semmle.util.trap.TrapWriter; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardCopyOption; /** * A trap writer for use with...
2,675
34.68
100
java
codeql
codeql-master/java/ql/src/Frameworks/Spring/Architecture/Refactoring Opportunities/UnusedBean.java
class Start { public static void main(String[] args) { // Create a context from the XML file, constructing beans ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"services.xml"}); // Retrieve the petStore from the context bean factory. PetStoreService service = context.getBe...
435
35.333333
79
java
codeql
codeql-master/java/ql/src/Frameworks/Spring/Violations of Best Practice/UseSetterInjectionGood.java
// Class for bean 'chart2' public class ChartMaker { private AxisRenderer axisRenderer = new DefaultAxisRenderer(); private TrendRenderer trendRenderer = new DefaultTrendRenderer(); public ChartMaker() {} public void setAxisRenderer(AxisRenderer axisRenderer) { this.axisRenderer = axisRenderer; } public v...
414
26.666667
66
java
codeql
codeql-master/java/ql/src/Frameworks/Spring/Violations of Best Practice/UseSetterInjection.java
// Class for bean 'chart1' public class WrongChartMaker { private AxisRenderer axisRenderer = new DefaultAxisRenderer(); private TrendRenderer trendRenderer = new DefaultTrendRenderer(); public WrongChartMaker() {} // Each combination of the optional parameters must be represented by a constructor. public Wrong...
715
31.545455
85
java
codeql
codeql-master/java/ql/src/Frameworks/Spring/XML Configuration Errors/MissingSetters.java
// bean class public class ContentService { private TransactionHelper helper; // This method does not match the property in the bean file. public void setHelper(TransactionHelper helper) { this.helper = helper; } }
222
21.3
61
java
codeql
codeql-master/java/ql/src/Advisory/Statements/TerminateIfElseIfWithElseGood.java
int score; char grade; // ... if (score >= 90) { grade = 'A'; } else if (score >= 80) { grade = 'B'; } else if (score >= 70) { grade = 'C'; } else if (score >= 60) { grade = 'D'; } else { // GOOD: Terminating 'else' clause for all other scores grade = 'F'; } System.out.println("Grade = " + grade)...
321
17.941176
65
java
codeql
codeql-master/java/ql/src/Advisory/Statements/TerminateIfElseIfWithElse.java
int score; char grade; // ... if (score >= 90) { grade = 'A'; } else if (score >= 80) { grade = 'B'; } else if (score >= 70) { grade = 'C'; } else if (score >= 60) { grade = 'D'; // BAD: No terminating 'else' clause } System.out.println("Grade = " + grade);
277
16.375
39
java
codeql
codeql-master/java/ql/src/Advisory/Statements/MissingDefaultInSwitchGood.java
int menuChoice; // ... switch (menuChoice) { case 1: System.out.println("You chose number 1."); break; case 2: System.out.println("You chose number 2."); break; case 3: System.out.println("You chose number 3."); break; default: // GOOD: 'default' case f...
421
22.444444
65
java
codeql
codeql-master/java/ql/src/Advisory/Statements/MissingDefaultInSwitch.java
int menuChoice; // ... switch (menuChoice) { case 1: System.out.println("You chose number 1."); break; case 2: System.out.println("You chose number 2."); break; case 3: System.out.println("You chose number 3."); break; // BAD: No 'default' case }
312
18.5625
50
java
codeql
codeql-master/java/ql/src/Advisory/Types/Generics_Common.java
public List constructRawList(Object o) { List list; // Raw variable declaration list = new ArrayList(); // Raw constructor call list.add(o); return list; // Raw method return type (see signature above) }
222
36.166667
65
java
codeql
codeql-master/java/ql/src/Advisory/Types/Generics_CommonGood.java
public <T> List<T> constructParameterizedList(T o) { List<T> list; // Parameterized variable declaration list = new ArrayList<T>(); // Parameterized constructor call list.add(o); return list; // Parameterized method return type (see signature above) }
270
44.166667
75
java
codeql
codeql-master/java/ql/src/Advisory/Documentation/MissingJavadocMethods.java
/** * Extracts the user's name from the input arguments. * * Precondition: 'args' should contain at least one element, the user's name. * * @param args the command-line arguments. * @return the user's name (the first command-line argument). * @throws NoNameException if 'args' contains...
493
29.875
77
java
codeql
codeql-master/java/ql/src/Advisory/Documentation/MissingJavadocTypes.java
/** * The Stack class represents a last-in-first-out stack of objects. * * @author Joseph Bergin * @version 1.0, May 2000 * Note that this version is not thread safe. */ public class Stack { // ...
206
22
68
java
codeql
codeql-master/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrowsFix.java
/** * Javadoc for method. */ public void noThrow() { System.out.println("This method does not throw."); }
108
17.166667
51
java
codeql
codeql-master/java/ql/src/Advisory/Documentation/SpuriousJavadocParam.java
/** * BAD: The following param tag is empty. * * @param */ public void emptyParamTag(int p){ ... } /** * BAD: The following param tag has a misspelled value. * * @param prameter The parameter's value. */ public void typo(int parameter){ ... } /** * BAD: The following param tag appears to be outdated ...
1,108
19.924528
63
java
codeql
codeql-master/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.java
/** * Javadoc for method. * * @throws Exception if a problem occurs. */ public void noThrow() { System.out.println("This method does not throw."); }
153
18.25
51
java
codeql
codeql-master/java/ql/src/Advisory/Declarations/MissingOverrideAnnotation.java
class Rectangle { private int w = 10, h = 10; public int getArea() { return w * h; } } class Triangle extends Rectangle { @Override // Annotation of an overriding method public int getArea() { return super.getArea() / 2; } }
272
17.2
53
java
codeql
codeql-master/java/ql/src/Advisory/Java Objects/AvoidCloneableInterface.java
public final class Galaxy { // This is the original constructor. public Galaxy (double aMass, String aName) { fMass = aMass; fName = aName; } // This is the copy constructor. public Galaxy(Galaxy aGalaxy) { this(aGalaxy.getMass(), aGalaxy.getName()); } // ... }
316
20.133333
51
java
codeql
codeql-master/java/ql/src/Metrics/Callables/CNumberOfParameters2.java
void printMembership(Set<Fellow> fellows, Set<Member> members, Set<Associate> associates, Set<Student> students) { for(Fellow f: fellows) { System.out.println(f); } for(Member m: members) { System.out.println(m); } for(Associate a: associates) { System.o...
506
24.35
72
java
codeql
codeql-master/java/ql/src/Metrics/Callables/CNumberOfParameters1.java
void printAnnotation(String annotationMessage, int annotationLine, int annotationOffset, int annotationLength) { System.out.println("Message: " + annotationMessage); System.out.println("Line: " + annotationLine); System.out.println("Offset: " + annotationOffset); System.out.println(...
351
57.666667
88
java
codeql
codeql-master/java/ql/src/Metrics/Callables/CNumberOfParameters1Good.java
class Annotation { //... } void printAnnotation(Annotation annotation) { System.out.println("Message: " + annotation.getMessage()); System.out.println("Line: " + annotation.getLine()); System.out.println("Offset: " + annotation.getOffset()); System.out.println("Length: " + annotation.getLength()); ...
321
31.2
62
java
codeql
codeql-master/java/ql/src/Metrics/Callables/CNumberOfParameters2Good.java
void printFellows(Set<Fellow> fellows) { for(Fellow f: fellows) { System.out.println(f); } } //... void printRecords() { //... printFellows(fellows); printMembers(members); printAssociates(associates); printStudents(students); }
266
16.8
40
java
codeql
codeql-master/java/ql/src/Metrics/Callables/CCyclomaticComplexity.java
int f(int i, int j) { int result; if(i % 2 == 0) { result = i + j; } else { if(j % 2 == 0) { result = i * j; } else { result = i - j; } } return result; }
242
15.2
27
java
codeql
codeql-master/java/ql/src/Metrics/Callables/StatementNestingDepthGood.java
public static void printAllCharInts(String s) { if (s != null) { for (int i = 0; i < s.length(); i++) { System.out.println(s.charAt(i) + "=" + (int) s.charAt(i)); } } } public static void printCharacterCodes_Good(String[] strings) { if (strings != null) { for(String s : s...
379
26.142857
70
java
codeql
codeql-master/java/ql/src/Metrics/Callables/StatementNestingDepth.java
public static void printCharacterCodes_Bad(String[] strings) { if (strings != null) { for (String s : strings) { if (s != null) { for (int i = 0; i < s.length(); i++) { System.out.println(s.charAt(i) + "=" + (int) s.charAt(i)); } } ...
337
29.727273
78
java
codeql
codeql-master/java/ql/src/Metrics/RefTypes/TSpecialisationIndex.java
abstract class Animal { protected String animalName; public Animal(String name) { animalName = name; } public String getName(){ return animalName; } public abstract String getKind(); } class Dog extends Animal { public Dog(String name) { super(name); } pub...
802
18.585366
83
java
codeql
codeql-master/java/ql/src/Metrics/RefTypes/TEfferentCouplingGood.java
class YX { public void iUseY(Y y) { y.doStuff(); } public Y soDoY() { return new Y(); } } class ZX { public Z iUseZ(Z z1, Z z2) { return z1.combine(z2); } }
206
12.8
32
java
codeql
codeql-master/java/ql/src/Metrics/RefTypes/TNumberOfFieldsGood.java
class Name { private String m_firstName; private String m_lastName; // ... } class Address { private int m_houseNumber; private String m_street; private String m_settlement; private Country m_country; private Postcode m_postcode; // ... } class Person { private Name m_name; ...
360
17.05
32
java
codeql
codeql-master/java/ql/src/Metrics/RefTypes/TEfferentCoupling.java
class X { public void iUseY(Y y) { y.doStuff(); } public Y soDoY() { return new Y(); } public Z iUseZ(Z z1, Z z2) { return z1.combine(z2); } }
192
13.846154
32
java
codeql
codeql-master/java/ql/src/Metrics/RefTypes/TSpecialisationIndexGood.java
abstract class Animal { private String animalName; public Animal(String name) { animalName = name; } public String getName() { // Method has been pulled up into the base class. return animalName + " the " + getKind(); } public abstract String getKind(); } class Dog extends ...
593
16.470588
80
java
codeql
codeql-master/java/ql/src/Metrics/RefTypes/TNumberOfFields.java
class Person { private String m_firstName; private String m_LastName; private int m_houseNumber; private String m_street; private String m_settlement; private Country m_country; private Postcode m_postcode; // ... }
247
23.8
32
java
codeql
codeql-master/java/ql/src/Metrics/Files/FCyclomaticComplexity.java
int f(int i, int j) { // start int result; if(i % 2 == 0) { // iEven result = i + j; } else { // iOdd if(j % 2 == 0) { // jEven result = i * j; } else { // jOdd result = i - j; } } return ...
340
15.238095
27
java
codeql
codeql-master/java/ql/src/external/DuplicateMethod.java
class RowWidget extends Widget { // ... public void collectChildren(Set<Widget> result) { for (Widget child : this.children) { if (child.isVisible()) { result.add(children); child.collectChildren(result); } } } } class ColumnWidget extends Widget { // ... public void collectChildren(Set<Widget> ...
471
19.521739
50
java
codeql
codeql-master/java/ql/src/external/DuplicateAnonymous.java
// BAD: Duplicate anonymous classes: button1.addActionListener(new ActionListener() { public void actionPerfored(ActionEvent e) { for (ActionListener listener: listeners) listeners.actionPerformed(e); } }); button2.addActionListener(new ActionListener() { public void actionPerfored(...
820
25.483871
54
java
codeql
codeql-master/java/ql/src/Performance/NewStringString.java
public void sayHello(String world) { // AVOID: Inefficient 'String' constructor String message = new String("hello "); // AVOID: Inefficient 'String' constructor message = new String(message + world); // AVOID: Inefficient 'String' constructor System.out.println(new String(message)); }
294
28.5
43
java
codeql
codeql-master/java/ql/src/Performance/InefficientOutputStreamGood.java
public class DigestCheckingFileOutputStream extends OutputStream { private DigestOutputStream digest; private byte[] expectedMD5; public DigestCheckingFileOutputStream(File file, byte[] expectedMD5) throws IOException, NoSuchAlgorithmException { this.expectedMD5 = expectedMD5; digest = new DigestOutputStrea...
838
24.424242
69
java
codeql
codeql-master/java/ql/src/Performance/ConcatenationInLoops.java
public class ConcatenationInLoops { public static void main(String[] args) { Random r = new Random(123); long start = System.currentTimeMillis(); String s = ""; for (int i = 0; i < 65536; i++) s += r.nextInt(2); System.out.println(System.currentTimeMillis() - start); // This prints roughly 4500. r = n...
580
31.277778
87
java
codeql
codeql-master/java/ql/src/Performance/InefficientToArray.java
class Company { private List<Customer> customers = ...; public Customer[] getCustomerArray() { // AVOID: Inefficient call to 'toArray' with zero-length argument return customers.toArray(new Customer[0]); } } class Company { private List<Customer> customers = ...; public Customer[] getCustomerArray() { /...
749
25.785714
94
java
codeql
codeql-master/java/ql/src/Performance/InefficientPrimConstructor.java
public class Account { private Integer balance; public Account(Integer startingBalance) { this.balance = startingBalance; } } public class BankManager { public void openAccount(Customer c) { ... // AVOID: Inefficient primitive constructor accounts.add(new Account(new Integer(0))); // GOOD: Use 'valueOf' ...
435
23.222222
48
java
codeql
codeql-master/java/ql/src/Performance/InefficientKeySetIterator.java
// AVOID: Iterate the map using the key set. class AddressBook { private Map<String, Person> people = ...; public String findId(String first, String last) { for (String id : people.keySet()) { Person p = people.get(id); if (first.equals(p.firstName()) && last.equals(p.lastName())) return id; } return ...
696
26.88
64
java
codeql
codeql-master/java/ql/src/Performance/InefficientOutputStreamBad.java
public class DigestCheckingFileOutputStream extends OutputStream { private DigestOutputStream digest; private byte[] expectedMD5; public DigestCheckingFileOutputStream(File file, byte[] expectedMD5) throws IOException, NoSuchAlgorithmException { this.expectedMD5 = expectedMD5; digest = new DigestOutputStrea...
726
24.964286
69
java
codeql
codeql-master/java/ql/src/Performance/InefficientEmptyStringTest.java
// Inefficient version class InefficientDBClient { public void connect(String user, String pw) { if (user.equals("") || "".equals(pw)) throw new RuntimeException(); ... } } // More efficient version class EfficientDBClient { public void connect(String user, String pw) { if (user.length() == 0 || (pw != nul...
388
20.611111
61
java
codeql
codeql-master/java/ql/src/Architecture/Dependencies/MutualDependencyFix.java
public class NoMutualDependency { // Better: A new interface breaks the dependency // from the model to the view private interface ModelListener { void modelChanged(); } private static class BetterModel { private int i; private ModelListener listener; public int getI() { return i; } public void s...
1,134
21.254902
59
java
codeql
codeql-master/java/ql/src/Architecture/Dependencies/MutualDependency.java
public class MutualDependency { // Violation: BadModel and BadView are mutually dependent private static class BadModel { private int i; private BadView view; public int getI() { return i; } public void setI(int i) { this.i = i; if(view != null) view.modelChanged(); } public void setView(Bad...
580
17.15625
58
java
codeql
codeql-master/java/ql/src/Architecture/Refactoring Opportunities/DeeplyNestedClass.java
class X1 { private int i; public X1(int i) { this.i = i; } public Y1 makeY1(float j) { return new Y1(j); } class Y1 { private float j; public Y1(float j) { this.j = j; } public Z1 makeZ1(double k) { return new Z1(k); } // Violation class Z1 { private double k; public Z1(double...
545
12.317073
45
java
codeql
codeql-master/java/ql/src/Architecture/Refactoring Opportunities/DeeplyNestedClassFix.java
class X2 { private int i; public X2(int i) { this.i = i; } public Y2 makeY2(float j) { return new Y2(i, j); } } class Y2 { private int i; private float j; public Y2(int i, float j) { this.i = i; this.j = j; } public Z2 makeZ2(double k) { return new Z2(i, j, k); } } class Z2 { private int i; ...
625
12.319149
45
java
codeql
codeql-master/java/ql/src/Architecture/Refactoring Opportunities/FeatureEnvy.java
// Before refactoring: class Item { .. } class Basket { // .. float getTotalPrice(Item i) { float price = i.getPrice() + i.getTax(); if (i.isOnSale()) price = price - i.getSaleDiscount() * price; return price; } } // After refactoring: class Item { // .. float getTotalPrice() { float price = getPrice()...
417
18
47
java
codeql
codeql-master/java/ql/src/Violations of Best Practice/Undesirable Calls/CallsToSystemExit.java
// Problem 1: Miss out cleanup code class FileOutput { boolean write(String[] s) { try { output.write(s.getBytes()); } catch (IOException e) { System.exit(1); } return true; } } // Problem 2: Make code reuse difficult class Action { public void run()...
496
19.708333
44
java
codeql
codeql-master/java/ql/src/Violations of Best Practice/Undesirable Calls/GarbageCollection.java
class RequestHandler extends Thread { private boolean isRunning; private Connection conn = new Connection(); public void run() { while (isRunning) { Request req = conn.getRequest(); // Process the request ... System.gc(); // This call may cause a garbage collection after each request. // Th...
468
30.266667
80
java