Skip to content

Commit a3088ae

Browse files
authored
Merge pull request #40 from RandomCodeSpace/fix/reliability-bugs
fix: resolve all 9 SonarCloud reliability bugs
2 parents 95292e1 + ec5180d commit a3088ae

6 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/main/java/io/github/randomcodespace/iq/detector/config/GitHubActionsDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public DetectorResult detect(DetectorContext ctx) {
8080
if (onTriggers == null) {
8181
// SnakeYAML may parse bare 'on' key as Boolean.TRUE — search by entry value
8282
onTriggers = data.entrySet().stream()
83-
.filter(e -> Boolean.TRUE.equals(e.getKey()))
83+
.filter(e -> "true".equals(String.valueOf(e.getKey())))
8484
.map(java.util.Map.Entry::getValue)
8585
.findFirst()
8686
.orElse(null);

src/main/java/io/github/randomcodespace/iq/detector/csharp/CSharpStructuresDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ protected DetectorResult detectWithRegex(DetectorContext ctx) {
211211
String path = httpPath != null ? httpPath : "";
212212
String fullPath;
213213
if (finalClassRoute != null) {
214-
fullPath = "/" + finalClassRoute.replaceAll("(^/+|/+$)", "");
214+
fullPath = "/" + finalClassRoute.replaceAll("(^/+)|(/+$)", "");
215215
if (!path.isEmpty()) fullPath = fullPath + "/" + path.replaceAll("^/+", "");
216216
} else {
217217
fullPath = !path.isEmpty() ? "/" + path.replaceAll("^/+", "") : "/";

src/main/java/io/github/randomcodespace/iq/detector/java/GrpcServiceDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class GrpcServiceDetector extends AbstractRegexDetector {
3333
private static final Pattern GRPC_IMPL_RE = Pattern.compile(
3434
"class\\s+(\\w+)\\s+extends\\s+(\\w+)Grpc\\.(\\w+)ImplBase");
3535
private static final Pattern METHOD_RE = Pattern.compile(
36-
"public\\s+(?:void|[\\w<>\\[\\]]+)\\s+(\\w+)\\s*\\(\\s*(\\w+)");
36+
"public\\s+[\\w<>\\[\\]]+\\s+(\\w+)\\s*\\(\\s*(\\w+)");
3737
private static final Pattern GRPC_STUB_RE = Pattern.compile(
3838
"(\\w+)Grpc\\.new(?:Blocking|Future)?Stub\\s*\\(");
3939

src/main/java/io/github/randomcodespace/iq/detector/java/JpaEntityDetector.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ private String resolveTargetEntity(AnnotationExpr ann, FieldDeclaration field) {
197197
Type type = var.getType();
198198
if (!type.isClassOrInterfaceType()) continue;
199199
ClassOrInterfaceType cit = type.asClassOrInterfaceType();
200-
if (cit.getTypeArguments().isPresent()) {
201-
var typeArgs = cit.getTypeArguments().get();
200+
var typeArgsOpt = cit.getTypeArguments();
201+
if (typeArgsOpt.isPresent()) {
202+
var typeArgs = typeArgsOpt.get();
202203
if (!typeArgs.isEmpty()) return typeArgs.get(0).asString();
203204
} else {
204205
return cit.getNameAsString();

src/main/java/io/github/randomcodespace/iq/detector/java/RawSqlDetector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public class RawSqlDetector extends AbstractRegexDetector {
2727

2828
private static final Pattern CLASS_RE = Pattern.compile("(?:public\\s+)?class\\s+(\\w+)");
2929
private static final Pattern QUERY_ANNO_RE = Pattern.compile(
30-
"@Query\\s*\\(\\s*(?:value\\s*=\\s*)?\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"", Pattern.DOTALL);
30+
"@Query\\s*\\(\\s*(?:value\\s*=\\s*)?\"([^\"\\\\]*+(?:\\\\.[^\"\\\\]*+)*+)\"", Pattern.DOTALL);
3131
private static final Pattern NATIVE_QUERY_RE = Pattern.compile("nativeQuery\\s*=\\s*true");
3232
private static final Pattern JDBC_TEMPLATE_RE = Pattern.compile(
3333
"(?:jdbcTemplate|namedParameterJdbcTemplate|JdbcTemplate)\\s*\\."
3434
+ "(?:query|queryForObject|queryForList|queryForMap|update|execute|batchUpdate)"
35-
+ "\\s*\\(\\s*\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"", Pattern.DOTALL);
35+
+ "\\s*\\(\\s*\"([^\"\\\\]*+(?:\\\\.[^\"\\\\]*+)*+)\"", Pattern.DOTALL);
3636
private static final Pattern EM_QUERY_RE = Pattern.compile(
37-
"(?:entityManager|em)\\s*\\.(?:createNativeQuery|createQuery)\\s*\\(\\s*\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"",
37+
"(?:entityManager|em)\\s*\\.(?:createNativeQuery|createQuery)\\s*\\(\\s*\"([^\"\\\\]*+(?:\\\\.[^\"\\\\]*+)*+)\"",
3838
Pattern.DOTALL);
3939
private static final Pattern TABLE_REF_RE = Pattern.compile(
4040
"\\b(?:FROM|JOIN|INTO|UPDATE|TABLE)\\s+(\\w+)", Pattern.CASE_INSENSITIVE);

src/main/java/io/github/randomcodespace/iq/detector/typescript/NestJSControllerDetector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ public class NestJSControllerDetector extends AbstractAntlrDetector {
4141
private static final Pattern NESTJS_IMPORT = Pattern.compile("from\\s+['\"]@nestjs/");
4242

4343
private static final Pattern CONTROLLER_PATTERN = Pattern.compile(
44-
"@Controller\\(\\s*['\"`]?([^'\"`\\)\\s]*)['\"`]?\\s*\\)(?:\\s*@\\w+\\([^)]{0,200}\\))*\\s*\\n\\s*(?:export\\s+)?class\\s+(\\w+)"
44+
"@Controller\\(\\s*['\"`]?([^'\"`\\)\\s]*)['\"`]?\\s*\\)(?:\\s*+@\\w+\\([^)]{0,200}\\))*+\\s*\\n\\s*(?:export\\s+)?class\\s+(\\w+)"
4545
);
4646

4747
private static final Pattern ROUTE_PATTERN = Pattern.compile(
48-
"@(Get|Post|Put|Delete|Patch|Options|Head)\\(\\s*['\"`]?([^'\"`\\)\\s]*)['\"`]?\\s*\\)(?:\\s*@\\w+\\([^)]{0,200}\\))*\\s*\\n\\s*(?:async\\s+)?(\\w+)"
48+
"@(Get|Post|Put|Delete|Patch|Options|Head)\\(\\s*['\"`]?([^'\"`\\)\\s]*)['\"`]?\\s*\\)(?:\\s*+@\\w+\\([^)]{0,200}\\))*+\\s*\\n\\s*(?:async\\s+)?(\\w+)"
4949
);
5050

5151
@Override

0 commit comments

Comments
 (0)