Skip to content

Commit

Permalink
Clean code after static code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenneg committed Nov 9, 2019
1 parent 60be0d9 commit d0db97f
Show file tree
Hide file tree
Showing 32 changed files with 118 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
if ("docker".equals(containerRuntime)) {
String uid = getLinuxID("-ur");
String gid = getLinuxID("-gr");
if (uid != null & gid != null & !"".equals(uid) & !"".equals(gid)) {
if (uid != null && gid != null && !"".equals(uid) && !"".equals(gid)) {
Collections.addAll(nativeImage, "--user", uid + ":" + gid);
}
} else if ("podman".equals(containerRuntime)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ private JsonObject processDependency(Artifact artifact) throws IOException {
if (onode != null) {
// TODO: this is a dirty hack to avoid redoing existing javax.json code
String json = getMapper(false).writeValueAsString(onode);
JsonReader jsonReader = Json.createReader(new StringReader(json));
return jsonReader.readObject();
try (JsonReader jsonReader = Json.createReader(new StringReader(json))) {
return jsonReader.readObject();
}
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ public void registerField(FieldInfo fieldInfo) {
case SERVICE_PROVIDER:
generatedResource.produce(
new GeneratedResourceBuildItem("META-INF/services/" + resource.getName(), resource.getData()));
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.quarkus.elytron.security.runtime;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -84,9 +86,11 @@ public void run() {
throw new IllegalStateException(msg);
}
LegacyPropertiesSecurityRealm propsRealm = (LegacyPropertiesSecurityRealm) secRealm;
propsRealm.load(users.openStream(), roles.openStream());
try (InputStream usersStream = users.openStream(); InputStream rolesStream = roles.openStream()) {
propsRealm.load(usersStream, rolesStream);
}
} catch (IOException e) {
throw new RuntimeException(e);
throw new UncheckedIOException(e);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,22 @@ public SecurityIdentity get() {
return null;
}
PasswordCredential cred = id.getCredential(PasswordCredential.class);
ServerAuthenticationContext ac = domain.createNewAuthenticationContext();
ac.setAuthenticationName(request.getPrincipal());
ac.addPrivateCredential(cred);
ac.authorize();
result = ac.getAuthorizedIdentity();
try (ServerAuthenticationContext ac = domain.createNewAuthenticationContext()) {
ac.setAuthenticationName(request.getPrincipal());
ac.addPrivateCredential(cred);
ac.authorize();
result = ac.getAuthorizedIdentity();

if (result == null) {
throw new AuthenticationFailedException();
if (result == null) {
throw new AuthenticationFailedException();
}
QuarkusSecurityIdentity.Builder builder = QuarkusSecurityIdentity.builder();
builder.setPrincipal(result.getPrincipal());
for (String i : result.getRoles()) {
builder.addRole(i);
}
return builder.build();
}
QuarkusSecurityIdentity.Builder builder = QuarkusSecurityIdentity.builder();
builder.setPrincipal(result.getPrincipal());
for (String i : result.getRoles()) {
builder.addRole(i);
}
return builder.build();
} catch (RealmUnavailableException e) {
throw new RuntimeException(e);
} catch (SecurityException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Map;

import org.apache.kafka.common.serialization.Deserializer;
Expand Down Expand Up @@ -34,7 +35,7 @@ public byte[] serialize(String topic, T data) {
objectMapper.writeValue(output, data);
return output.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
throw new UncheckedIOException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class VertxHttpResponse implements HttpResponse {

public VertxHttpResponse(HttpServerRequest request, ResteasyProviderFactory providerFactory,
final HttpMethod method, BufferAllocator allocator, VertxOutput output) {
outputHeaders = new MultivaluedMapImpl<String, Object>();
outputHeaders = new MultivaluedMapImpl<>();
this.method = method;
os = (method == null || !method.equals(HttpMethod.HEAD)) ? new VertxOutputStream(this, allocator)
: null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static ResteasyHttpHeaders extractHttpHeaders(HttpServerRequest request)
}

static Map<String, Cookie> extractCookies(MultivaluedMap<String, String> headers) {
Map<String, Cookie> cookies = new HashMap<String, Cookie>();
Map<String, Cookie> cookies = new HashMap<>();
List<String> cookieHeaders = headers.get("Cookie");
if (cookieHeaders == null)
return cookies;
Expand All @@ -78,7 +78,7 @@ static Map<String, Cookie> extractCookies(MultivaluedMap<String, String> headers
}

public static List<MediaType> extractAccepts(MultivaluedMap<String, String> requestHeaders) {
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
List<MediaType> acceptableMediaTypes = new ArrayList<>();
List<String> accepts = requestHeaders.get(HttpHeaderNames.ACCEPT);
if (accepts == null)
return acceptableMediaTypes;
Expand All @@ -90,7 +90,7 @@ public static List<MediaType> extractAccepts(MultivaluedMap<String, String> requ
}

public static List<String> extractLanguages(MultivaluedMap<String, String> requestHeaders) {
List<String> acceptable = new ArrayList<String>();
List<String> acceptable = new ArrayList<>();
List<String> accepts = requestHeaders.get(HttpHeaderNames.ACCEPT_LANGUAGE);
if (accepts == null)
return acceptable;
Expand All @@ -104,7 +104,7 @@ public static List<String> extractLanguages(MultivaluedMap<String, String> reque
}

public static MultivaluedMap<String, String> extractRequestHeaders(HttpServerRequest request) {
Headers<String> requestHeaders = new Headers<String>();
Headers<String> requestHeaders = new Headers<>();

for (Map.Entry<String, String> header : request.headers()) {
requestHeaders.add(header.getKey(), header.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public CompletionStage<SecurityIdentity> authenticate(TokenAuthenticationRequest

} catch (ParseException | MalformedClaimException e) {
log.debug("Authentication failed", e);
CompletableFuture<SecurityIdentity> cf = new CompletableFuture<SecurityIdentity>();
CompletableFuture<SecurityIdentity> cf = new CompletableFuture<>();
cf.completeExceptionally(new AuthenticationFailedException());
return cf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Result parse(MethodInfo methodInfo) {
boolean allIgnoreCase = false;
if (afterByPart.contains(ALL_IGNORE_CASE)) {
allIgnoreCase = true;
afterByPart = afterByPart.replaceAll(ALL_IGNORE_CASE, "");
afterByPart = afterByPart.replace(ALL_IGNORE_CASE, "");
}

// handle the 'OrderBy' clause which is assumed to be at the end of the query
Expand All @@ -131,10 +131,10 @@ public Result parse(MethodInfo methodInfo) {
boolean ascending = true;
if (afterOrderByPart.endsWith("Asc")) {
ascending = true;
afterOrderByPart = afterOrderByPart.replaceAll("Asc", "");
afterOrderByPart = afterOrderByPart.replace("Asc", "");
} else if (afterOrderByPart.endsWith("Desc")) {
ascending = false;
afterOrderByPart = afterOrderByPart.replaceAll("Desc", "");
afterOrderByPart = afterOrderByPart.replace("Desc", "");
}
String orderField = lowerFirstLetter(afterOrderByPart);
if (!entityContainsField(orderField)) {
Expand Down Expand Up @@ -176,7 +176,7 @@ public Result parse(MethodInfo methodInfo) {

if (part.endsWith(IGNORE_CASE)) {
ignoreCase = true;
part = part.replaceAll(IGNORE_CASE, "");
part = part.replace(IGNORE_CASE, "");
}

String operation = getFieldOperation(part);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void registerSwaggerUiServletExtension(SwaggerUiRecorder recorder,
cached.cachedDirectory = tempDir.toAbsolutePath().toString();
cached.cachedOpenAPIPath = openApiPath;
} catch (IOException e) {
throw new RuntimeException(e);
throw new UncheckedIOException(e);
}
}
Handler<RoutingContext> handler = recorder.handler(cached.cachedDirectory, swaggerUiConfig.path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
Expand Down Expand Up @@ -123,7 +124,7 @@ private Set<WebFragmentMetaData> parseWebFragments(ApplicationArchivesBuildItem
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to parse " + webFragment + " " + e.getLocation(), e);
} catch (IOException e) {
throw new RuntimeException("Failed to parse " + webFragment, e);
throw new UncheckedIOException("Failed to parse " + webFragment, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -124,7 +125,7 @@ public List<Resource> list() {
try {
ret.add(underlying.getResource(i));
} catch (IOException e) {
throw new RuntimeException(e);
throw new UncheckedIOException(e);
}
} else {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static io.quarkus.vault.runtime.config.VaultAuthenticationType.USERPASS;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -129,7 +130,7 @@ private byte[] read(String path) {
try {
return Files.readAllBytes(Paths.get(path));
} catch (IOException e) {
throw new RuntimeException(e);
throw new UncheckedIOException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,97 +69,97 @@ final class Target_io_vertx_core_eventbus_impl_clustered_ClusteredEventBusCluste

@Substitute
private NetServerOptions getServerOptions() {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
static void setCertOptions(TCPSSLOptions options, KeyCertOptions keyCertOptions) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
static void setTrustOptions(TCPSSLOptions sslOptions, TrustOptions options) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
public void start(Handler<AsyncResult<Void>> resultHandler) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
public void close(Handler<AsyncResult<Void>> completionHandler) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");

}

@Substitute
public MessageImpl createMessage(boolean send, String address, MultiMap headers, Object body, String codecName,
Handler<AsyncResult<Void>> writeHandler) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
protected <T> void addRegistration(boolean newAddress, String address,
boolean replyHandler, boolean localOnly,
Handler<AsyncResult<Void>> completionHandler) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
protected <T> void removeRegistration(HandlerHolder<T> lastHolder, String address,
Handler<AsyncResult<Void>> completionHandler) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
protected String generateReplyAddress() {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
protected boolean isMessageLocal(MessageImpl msg) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
private void setClusterViewChangedHandler(HAManager haManager) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
private int getClusterPublicPort(EventBusOptions options, int actualPort) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
private String getClusterPublicHost(EventBusOptions options) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
private Handler<NetSocket> getServerHandler() {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
private void sendRemote(ServerID theServerID, MessageImpl message) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
private void removeSub(String subName, ClusterNodeInfo node, Handler<AsyncResult<Void>> completionHandler) {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
VertxInternal vertx() {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}

@Substitute
EventBusOptions options() {
throw new RuntimeException("Not Implemented");
throw new UnsupportedOperationException("Not Implemented");
}
}

Expand Down
Loading

0 comments on commit d0db97f

Please sign in to comment.