Skip to content

Commit 63e648f

Browse files
committed
Resolve some sonar bugs
1 parent f822ad3 commit 63e648f

File tree

7 files changed

+54
-40
lines changed

7 files changed

+54
-40
lines changed

operator/src/main/java/oracle/kubernetes/operator/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

@@ -478,7 +478,7 @@ public void run() {
478478
try {
479479
shutdownSignal.acquire();
480480
} catch (InterruptedException ignore) {
481-
// ignoring
481+
Thread.currentThread().interrupt();
482482
}
483483

484484
isNamespaceStopping.forEach(

operator/src/main/java/oracle/kubernetes/operator/ServerStatusReader.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018,2019 Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2018, 2019 Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

@@ -162,7 +162,9 @@ public NextAction apply(Packet packet) {
162162
state = CharStreams.toString(reader);
163163
}
164164
}
165-
} catch (IOException | ApiException | InterruptedException e) {
165+
} catch (InterruptedException ignore) {
166+
Thread.currentThread().interrupt();
167+
} catch (IOException | ApiException e) {
166168
LOGGER.warning(MessageKeys.EXCEPTION, e);
167169
} finally {
168170
helper.recycle(client);

operator/src/main/java/oracle/kubernetes/operator/Watcher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ void waitForExit() {
7878
if (thread != null) {
7979
thread.join();
8080
}
81-
} catch (InterruptedException ignored) {
81+
} catch (InterruptedException e) {
82+
Thread.currentThread().interrupt();
8283
}
8384
}
8485

@@ -128,6 +129,7 @@ private void watchForEvents() {
128129
Thread.sleep(delay);
129130
} catch (InterruptedException ex) {
130131
LOGGER.warning(MessageKeys.EXCEPTION, ex);
132+
Thread.currentThread().interrupt();
131133
}
132134
lastInitialize = System.currentTimeMillis();
133135
} else {

operator/src/main/java/oracle/kubernetes/operator/helpers/ConfigMapHelper.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ public NextAction apply(Packet packet) {
270270
if (topologyYaml != null) {
271271
LOGGER.fine("topology.yaml: " + topologyYaml);
272272
DomainTopology domainTopology = parseDomainTopologyYaml(topologyYaml);
273-
if (!domainTopology.getDomainValid()) {
273+
if (domainTopology == null || !domainTopology.getDomainValid()) {
274274
// If introspector determines Domain is invalid then log erros and terminate the fiber
275-
logValidationErrors(domainTopology.getValidationErrors());
275+
if (domainTopology != null) {
276+
logValidationErrors(domainTopology.getValidationErrors());
277+
}
276278
return doNext(null, packet);
277279
}
278280
WlsDomainConfig wlsDomainConfig = domainTopology.getDomain();
@@ -509,10 +511,14 @@ public NextAction onSuccess(Packet packet, CallResponse<V1ConfigMap> callRespons
509511
if (topologyYaml != null) {
510512
ConfigMapHelper.DomainTopology domainTopology =
511513
ConfigMapHelper.parseDomainTopologyYaml(topologyYaml);
512-
WlsDomainConfig wlsDomainConfig = domainTopology.getDomain();
513-
ScanCache.INSTANCE.registerScan(
514-
info.getNamespace(), info.getDomainUID(), new Scan(wlsDomainConfig, new DateTime()));
515-
packet.put(ProcessingConstants.DOMAIN_TOPOLOGY, wlsDomainConfig);
514+
if (domainTopology != null) {
515+
WlsDomainConfig wlsDomainConfig = domainTopology.getDomain();
516+
ScanCache.INSTANCE.registerScan(
517+
info.getNamespace(),
518+
info.getDomainUID(),
519+
new Scan(wlsDomainConfig, new DateTime()));
520+
packet.put(ProcessingConstants.DOMAIN_TOPOLOGY, wlsDomainConfig);
521+
}
516522
}
517523
}
518524

operator/src/main/java/oracle/kubernetes/operator/helpers/RollingHelper.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

@@ -222,8 +222,15 @@ public NextAction apply(Packet packet) {
222222
while (countReady-- > dom.getMinAvailable(clusterName)) {
223223
current = it.next();
224224
serverConfig = (WlsServerConfig) current.packet.get(ProcessingConstants.SERVER_SCAN);
225-
servers.add(
226-
serverConfig != null ? serverConfig.getName() : config.getAdminServerName());
225+
String serverName = null;
226+
if (serverConfig != null) {
227+
serverName = serverConfig.getName();
228+
} else if (config != null) {
229+
serverName = config.getAdminServerName();
230+
}
231+
if (serverName != null) {
232+
servers.add(serverName);
233+
}
227234
serversThatCanRestartNow.add(current);
228235
if (!it.hasNext()) {
229236
break;

operator/src/main/java/oracle/kubernetes/operator/rest/RequestDebugLoggingFilter.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

@@ -17,20 +17,19 @@
1717
import oracle.kubernetes.operator.logging.LoggingFactory;
1818
import org.glassfish.jersey.message.MessageUtils;
1919

20-
/** RequestDebugLoggingFilter debug logs all the REST Requests */
20+
/** RequestDebugLoggingFilter debug logs all the REST Requests. */
2121
@Provider
2222
@Priority(FilterPriorities.REQUEST_DEBUG_LOGGING_FILTER_PRIORITY)
2323
public class RequestDebugLoggingFilter extends BaseDebugLoggingFilter
2424
implements ContainerRequestFilter {
2525

2626
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
2727

28-
/** Construct a RequestDebugLoggingFilter */
28+
/** Construct a RequestDebugLoggingFilter. */
2929
public RequestDebugLoggingFilter() {
3030
// nothing to do
3131
}
3232

33-
/** {@inheritDoc} */
3433
@Override
3534
public void filter(ContainerRequestContext req) throws IOException {
3635
LOGGER.entering();
@@ -73,24 +72,25 @@ private String readEntityAsString(ContainerRequestContext req) throws Exception
7372
LOGGER.entering();
7473
// Read the entire input stream into a String
7574
// This should be OK since JSON input shouldn't be monstrously big
76-
BufferedReader ir = new BufferedReader(new InputStreamReader(req.getEntityStream()));
77-
StringBuilder sb = new StringBuilder();
78-
String line = null;
79-
Charset cs = MessageUtils.getCharset(req.getMediaType());
80-
// TBD - is all the Charset handling correct?
81-
do {
82-
line = ir.readLine();
83-
if (line != null) {
84-
sb.append(line);
85-
}
86-
} while (line != null);
87-
ir.close();
88-
String entity = sb.toString();
75+
try (BufferedReader ir = new BufferedReader(new InputStreamReader(req.getEntityStream()))) {
76+
StringBuilder sb = new StringBuilder();
77+
String line = null;
78+
Charset cs = MessageUtils.getCharset(req.getMediaType());
79+
// TBD - is all the Charset handling correct?
80+
do {
81+
line = ir.readLine();
82+
if (line != null) {
83+
sb.append(line);
84+
}
85+
} while (line != null);
86+
ir.close();
87+
String entity = sb.toString();
8988

90-
// Set the request input stream to a clone of the original input stream
91-
// so that it can be read again
92-
req.setEntityStream(new ByteArrayInputStream(entity.getBytes(cs)));
93-
LOGGER.exiting(entity);
94-
return entity;
89+
// Set the request input stream to a clone of the original input stream
90+
// so that it can be read again
91+
req.setEntityStream(new ByteArrayInputStream(entity.getBytes(cs)));
92+
LOGGER.exiting(entity);
93+
return entity;
94+
}
9595
}
9696
}

operator/src/main/java/oracle/kubernetes/operator/work/Container.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

@@ -22,9 +22,6 @@ private static final class NoneContainer extends Container {}
2222

2323
@Override
2424
public <S> S getSPI(Class<S> spiType) {
25-
if (components == null) {
26-
return null;
27-
}
2825
for (Component c : components.values()) {
2926
S s = c.getSPI(spiType);
3027
if (s != null) {

0 commit comments

Comments
 (0)