Merge pull request #7170 from gwenneg/sonarqube-blockers

Fix blocker issues detected with SonarCloud
This commit is contained in:
Guillaume Smet
2020-02-13 11:03:58 +01:00
committed by GitHub
7 changed files with 88 additions and 104 deletions

View File

@@ -43,15 +43,15 @@ public class ListExtensionsCommand implements Command<CommandInvocation> {
} else {
try {
BuildFile buildFile = null;
FileProjectWriter writer = null;
if (path != null) {
File projectDirectory = new File(path.getAbsolutePath());
writer = new FileProjectWriter(projectDirectory);
if (new File(projectDirectory, "build.gradle").exists()
|| new File(projectDirectory, "build.gradle.kts").exists()) {
buildFile = new GradleBuildFile(writer);
} else {
buildFile = new MavenBuildFile(writer);
try (FileProjectWriter writer = new FileProjectWriter(projectDirectory)) {
if (new File(projectDirectory, "build.gradle").exists()
|| new File(projectDirectory, "build.gradle.kts").exists()) {
buildFile = new GradleBuildFile(writer);
} else {
buildFile = new MavenBuildFile(writer);
}
}
}
new ListExtensions(buildFile).listExtensions(all, format, searchPattern);

View File

@@ -1,25 +0,0 @@
package io.quarkus.security.test;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
public class TestCharClone {
@Test
public void testClone() {
char[] password = "jb0ss".toCharArray();
char[] clone = password.clone();
if (clone == password) {
System.out.printf("Failure, clone == password%n");
}
if (!Arrays.equals(password, clone)) {
System.out.printf("Failure, clone neq password%n");
}
Class<? extends char[]> charArrayClass = password.getClass();
System.out.printf("char[](%s) methods:%n", charArrayClass.getName());
for (Method m : charArrayClass.getMethods()) {
System.out.println(m);
}
}
}

View File

@@ -115,6 +115,7 @@ public class QuartzScheduler implements Scheduler {
break;
case CRON4J:
cron = CronMapper.fromCron4jToQuartz().map(cronExpr).asString();
break;
default:
break;
}

View File

@@ -25,12 +25,13 @@ public class ScalaCompilationProvider implements CompilationProvider {
.forEach(f -> settings.classpath().append(f));
settings.outputDirs().add(context.getSourceDirectory().getAbsolutePath(),
context.getOutputDirectory().getAbsolutePath());
Global g = new Global(settings);
Global.Run run = g.new Run();
Set<String> fileSet = files.stream()
.map(File::getAbsolutePath)
.collect(Collectors.toSet());
run.compile(JavaConverters.asScalaSet(fileSet).toList());
try (Global g = new Global(settings)) {
Global.Run run = g.new Run();
Set<String> fileSet = files.stream()
.map(File::getAbsolutePath)
.collect(Collectors.toSet());
run.compile(JavaConverters.asScalaSet(fileSet).toList());
}
}
@Override

View File

@@ -63,6 +63,7 @@ public class WebXmlParsingBuildStep {
Set<String> additionalBeans = new HashSet<>();
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
inputFactory.setXMLResolver(dtdInfo);
try (InputStream in = Files.newInputStream(webXml)) {
@@ -113,6 +114,7 @@ public class WebXmlParsingBuildStep {
if (webFragment != null && Files.isRegularFile(webFragment)) {
try (InputStream is = Files.newInputStream(webFragment)) {
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
inputFactory.setXMLResolver(NoopXMLResolver.create());
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);

View File

@@ -203,26 +203,27 @@ public class ValueResolverGenerator {
if (methodParams.isEmpty()) {
LOGGER.debugf("Method added %s", method);
BytecodeCreator matchScope = createMatchScope(resolve, method.name(), methodParams.size(), name, params,
paramsCount);
try (BytecodeCreator matchScope = createMatchScope(resolve, method.name(), methodParams.size(), name,
params, paramsCount)) {
// Invoke the method - no params
ResultHandle ret;
boolean hasCompletionStage = !skipMemberType(method.returnType())
&& hasCompletionStageInTypeClosure(index.getClassByName(method.returnType().name()), index);
// Invoke the method - no params
ResultHandle ret;
boolean hasCompletionStage = !skipMemberType(method.returnType())
&& hasCompletionStageInTypeClosure(index.getClassByName(method.returnType().name()), index);
ResultHandle invokeRet;
if (Modifier.isInterface(clazz.flags())) {
invokeRet = matchScope.invokeInterfaceMethod(MethodDescriptor.of(method), base);
} else {
invokeRet = matchScope.invokeVirtualMethod(MethodDescriptor.of(method), base);
ResultHandle invokeRet;
if (Modifier.isInterface(clazz.flags())) {
invokeRet = matchScope.invokeInterfaceMethod(MethodDescriptor.of(method), base);
} else {
invokeRet = matchScope.invokeVirtualMethod(MethodDescriptor.of(method), base);
}
if (hasCompletionStage) {
ret = invokeRet;
} else {
ret = matchScope.invokeStaticMethod(Descriptors.COMPLETED_FUTURE, invokeRet);
}
matchScope.returnValue(ret);
}
if (hasCompletionStage) {
ret = invokeRet;
} else {
ret = matchScope.invokeStaticMethod(Descriptors.COMPLETED_FUTURE, invokeRet);
}
matchScope.returnValue(ret);
} else {
// Collect methods with params
@@ -395,58 +396,60 @@ public class ValueResolverGenerator {
for (MethodInfo method : entry.getValue()) {
// Try to match parameter types
BytecodeCreator paramMatchScope = success.createScope();
int idx = 0;
for (Type paramType : method.parameters()) {
ResultHandle paramHandleClass = paramMatchScope.readArrayValue(paramClasses, idx++);
ResultHandle testClass = loadParamType(paramMatchScope, paramType);
ResultHandle baseClassTest = paramMatchScope.invokeVirtualMethod(Descriptors.IS_ASSIGNABLE_FROM,
testClass,
paramHandleClass);
paramMatchScope.ifNonZero(baseClassTest).falseBranch().breakScope(paramMatchScope);
}
boolean hasCompletionStage = !skipMemberType(method.returnType())
&& hasCompletionStageInTypeClosure(index.getClassByName(method.returnType().name()), index);
try (BytecodeCreator paramMatchScope = success.createScope()) {
int idx = 0;
for (Type paramType : method.parameters()) {
ResultHandle paramHandleClass = paramMatchScope.readArrayValue(paramClasses, idx++);
ResultHandle testClass = loadParamType(paramMatchScope, paramType);
ResultHandle baseClassTest = paramMatchScope.invokeVirtualMethod(Descriptors.IS_ASSIGNABLE_FROM,
testClass,
paramHandleClass);
paramMatchScope.ifNonZero(baseClassTest).falseBranch().breakScope(paramMatchScope);
}
boolean hasCompletionStage = !skipMemberType(method.returnType())
&& hasCompletionStageInTypeClosure(index.getClassByName(method.returnType().name()), index);
AssignableResultHandle invokeRet = paramMatchScope.createVariable(Object.class);
// try
TryBlock tryCatch = paramMatchScope.tryBlock();
// catch (Throwable e)
CatchBlockCreator exception = tryCatch.addCatch(Throwable.class);
// CompletableFuture.completeExceptionally(Throwable)
exception.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE_EXCEPTIONALLY, whenRet,
exception.getCaughtException());
AssignableResultHandle invokeRet = paramMatchScope.createVariable(Object.class);
// try
TryBlock tryCatch = paramMatchScope.tryBlock();
// catch (Throwable e)
CatchBlockCreator exception = tryCatch.addCatch(Throwable.class);
// CompletableFuture.completeExceptionally(Throwable)
exception.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE_EXCEPTIONALLY, whenRet,
exception.getCaughtException());
if (Modifier.isInterface(clazz.flags())) {
tryCatch.assign(invokeRet,
tryCatch.invokeInterfaceMethod(MethodDescriptor.of(method), whenBase, paramsHandle));
} else {
tryCatch.assign(invokeRet,
tryCatch.invokeVirtualMethod(MethodDescriptor.of(method), whenBase, paramsHandle));
}
if (Modifier.isInterface(clazz.flags())) {
tryCatch.assign(invokeRet,
tryCatch.invokeInterfaceMethod(MethodDescriptor.of(method), whenBase, paramsHandle));
} else {
tryCatch.assign(invokeRet,
tryCatch.invokeVirtualMethod(MethodDescriptor.of(method), whenBase, paramsHandle));
}
if (hasCompletionStage) {
FunctionCreator invokeWhenCompleteFun = tryCatch.createFunction(BiConsumer.class);
tryCatch.invokeInterfaceMethod(Descriptors.CF_WHEN_COMPLETE, invokeRet,
invokeWhenCompleteFun.getInstance());
BytecodeCreator invokeWhenComplete = invokeWhenCompleteFun.getBytecode();
if (hasCompletionStage) {
FunctionCreator invokeWhenCompleteFun = tryCatch.createFunction(BiConsumer.class);
tryCatch.invokeInterfaceMethod(Descriptors.CF_WHEN_COMPLETE, invokeRet,
invokeWhenCompleteFun.getInstance());
BytecodeCreator invokeWhenComplete = invokeWhenCompleteFun.getBytecode();
// TODO workaround for https://github.com/quarkusio/gizmo/issues/6
AssignableResultHandle invokeWhenRet = invokeWhenComplete.createVariable(CompletableFuture.class);
invokeWhenComplete.assign(invokeWhenRet, whenRet);
// TODO workaround for https://github.com/quarkusio/gizmo/issues/6
AssignableResultHandle invokeWhenRet = invokeWhenComplete
.createVariable(CompletableFuture.class);
invokeWhenComplete.assign(invokeWhenRet, whenRet);
BranchResult invokeThrowableIsNull = invokeWhenComplete
.ifNull(invokeWhenComplete.getMethodParam(1));
BytecodeCreator invokeSuccess = invokeThrowableIsNull.trueBranch();
invokeSuccess.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE, invokeWhenRet,
invokeWhenComplete.getMethodParam(0));
BytecodeCreator invokeFailure = invokeThrowableIsNull.falseBranch();
invokeFailure.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE_EXCEPTIONALLY,
invokeWhenRet,
invokeWhenComplete.getMethodParam(1));
invokeWhenComplete.returnValue(null);
} else {
tryCatch.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE, whenRet, invokeRet);
BranchResult invokeThrowableIsNull = invokeWhenComplete
.ifNull(invokeWhenComplete.getMethodParam(1));
BytecodeCreator invokeSuccess = invokeThrowableIsNull.trueBranch();
invokeSuccess.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE, invokeWhenRet,
invokeWhenComplete.getMethodParam(0));
BytecodeCreator invokeFailure = invokeThrowableIsNull.falseBranch();
invokeFailure.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE_EXCEPTIONALLY,
invokeWhenRet,
invokeWhenComplete.getMethodParam(1));
invokeWhenComplete.returnValue(null);
} else {
tryCatch.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE, whenRet, invokeRet);
}
}
}

View File

@@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.Map;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.NamespacedKubernetesClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
@@ -18,8 +19,9 @@ public class KubernetesMockServerTestResource implements QuarkusTestResourceLife
mockServer.init();
final Map<String, String> systemProps = new HashMap<>();
systemProps.put(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY,
mockServer.createClient().getConfiguration().getMasterUrl());
try (NamespacedKubernetesClient client = mockServer.createClient()) {
systemProps.put(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, client.getConfiguration().getMasterUrl());
}
systemProps.put(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true");
systemProps.put(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false");
systemProps.put(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false");