Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "ASTHelpersSuggestions",
"language": "java",
"description": "Prefer ASTHelpers instead of calling this API directly",
"example": null,
"cwe": null,
"cwe-description": null,
"checker-language": "java",
"loc": 100,
"branches": 7,
"apis": 1,
"test": [
{
"description": "positive",
"expected-problems": null,
"expected-linenumbers": [
29
],
"code": "import com.sun.tools.javac.code.Symbol;\n\n class Test {\n void f(Symbol s) {\n s.isStatic();\n s.packge();\n }\n }\n \n\n import static com.google.errorprone.util.ASTHelpers.enclosingPackage;\n import static com.google.errorprone.util.ASTHelpers.isStatic;\n import com.sun.tools.javac.code.Symbol;\n\n class Test {\n void f(Symbol s) {\n isStatic(s);\n enclosingPackage(s);\n }\n }"
},
{
"description": "onSymbolSubtype",
"expected-problems": null,
"expected-linenumbers": [
63
],
"code": "import com.sun.tools.javac.code.Symbol.VarSymbol;\n\n class Test {\n void f(VarSymbol s) {\n s.isStatic();\n s.packge();\n }\n }\n \n\n import static com.google.errorprone.util.ASTHelpers.enclosingPackage;\n import com.sun.tools.javac.code.Symbol.VarSymbol;\n\n class Test {\n void f(VarSymbol s) {\n s.isStatic();\n enclosingPackage(s);\n }\n }"
},
{
"description": "symbolGetEnclosedElements",
"expected-problems": null,
"expected-linenumbers": [
96
],
"code": "import com.sun.tools.javac.code.Symbol.ClassSymbol;\n\n class Test {\n void f(ClassSymbol s) {\n s.getEnclosedElements();\n }\n }\n \n\n import static com.google.errorprone.util.ASTHelpers.getEnclosedElements;\n import com.sun.tools.javac.code.Symbol.ClassSymbol;\n\n class Test {\n void f(ClassSymbol s) {\n getEnclosedElements(s);\n }\n }"
},
{
"description": "selfMatch",
"expected-problems": null,
"expected-linenumbers": [
127
],
"code": "package com.google.errorprone.util;\n\n import com.sun.tools.javac.code.Symbol;\n\n public final class ASTHelpers {\n public static boolean isStatic(Symbol symbol) {\n return symbol.isStatic();\n }\n }"
},
{
"description": "symbolOwnerEnclClass",
"expected-problems": null,
"expected-linenumbers": [
149
],
"code": "import com.sun.tools.javac.code.Symbol.ClassSymbol;\n\n class Test {\n void f(ClassSymbol symbol) {\n ClassSymbol enclosing = symbol.owner.enclClass();\n }\n }\n \n\n import static com.google.errorprone.util.ASTHelpers.enclosingClass;\n import com.sun.tools.javac.code.Symbol.ClassSymbol;\n\n class Test {\n void f(ClassSymbol symbol) {\n ClassSymbol enclosing = enclosingClass(symbol);\n }\n }"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "AddressSelection",
"language": "java",
"description": "Prefer InetAddress.getAllByName to APIs that convert a hostname to a single IP address",
"example": null,
"cwe": null,
"cwe-description": null,
"checker-language": "java",
"loc": 116,
"branches": 11,
"apis": 1,
"test": [
{
"description": "positive",
"expected-problems": null,
"expected-linenumbers": [
34
],
"code": "import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n // BUG: Diagnostic contains:\n InetAddress.getByName(\"example.com\");\n // BUG: Diagnostic contains:\n new Socket(\"example.com\", 80);\n // BUG: Diagnostic contains:\n new InetSocketAddress(\"example.com\", 80);\n }\n }"
},
{
"description": "negative",
"expected-problems": null,
"expected-linenumbers": [
58
],
"code": "import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n new Socket(InetAddress.getLoopbackAddress(), 80);\n InetAddress.getAllByName(\"example.com\");\n new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);\n }\n }"
},
{
"description": "negativeLocalhost",
"expected-problems": null,
"expected-linenumbers": [
79
],
"code": "import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n new Socket(\"localhost\", 80);\n InetAddress.getByName(\"localhost\");\n new InetSocketAddress(\"localhost\", 80);\n }\n }"
},
{
"description": "negativeNumeric",
"expected-problems": null,
"expected-linenumbers": [
100
],
"code": "import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n new Socket(\"1.2.3.4\", 80);\n InetAddress.getByName(\"2001:db8:85a3:8d3:1319:8a2e:370:7348\");\n new InetSocketAddress(\"::ffff:192.0.2.128\", 80);\n }\n }"
},
{
"description": "refactor",
"expected-problems": null,
"expected-linenumbers": [
121
],
"code": "import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n new Socket(\"127.0.0.1\", 80);\n InetAddress.getByName(\"127.0.0.1\");\n new InetSocketAddress(\"127.0.0.1\", 80);\n new Socket(\"::1\", 80);\n InetAddress.getByName(\"::1\");\n new InetSocketAddress(\"::1\", 80);\n }\n }\n \n\n import java.net.InetAddress;\n import java.net.InetSocketAddress;\n import java.net.Socket;\n\n class Test {\n void f() throws Exception {\n new Socket(InetAddress.getLoopbackAddress(), 80);\n InetAddress.getLoopbackAddress();\n new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);\n new Socket(InetAddress.getLoopbackAddress(), 80);\n InetAddress.getLoopbackAddress();\n new InetSocketAddress(InetAddress.getLoopbackAddress(), 80);\n }\n }"
}
]
}
Loading