Skip to content

Commit 0c514c0

Browse files
committed
Cleanup errors and warnings
1 parent 3f92cc6 commit 0c514c0

File tree

233 files changed

+3715
-4442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+3715
-4442
lines changed

common/src/main/java/oracle/kubernetes/common/logging/BaseLoggingFacade.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.common.logging;
@@ -22,6 +22,7 @@ public abstract class BaseLoggingFacade {
2222
* Construct logging facade.
2323
* @param logger logger
2424
*/
25+
@SuppressWarnings("this-escape")
2526
protected BaseLoggingFacade(Logger logger) {
2627
this.logger = logger;
2728

@@ -245,7 +246,7 @@ public Level getLevel() {
245246
/**
246247
* Sets the level at which the underlying Logger operates. This should not be called in the
247248
* general case; levels should be set via OOB configuration (a configuration file exposed by the
248-
* logging implementation, management API, etc).
249+
* logging implementation, management API, etc.).
249250
*
250251
* @param newLevel Level to set
251252
*/
@@ -401,7 +402,7 @@ public boolean isWarningEnabled() {
401402
* Logs a message at the requested level. Normally, one of the level-specific methods should be
402403
* used instead.
403404
*
404-
* @param level Level at which log log the message
405+
* @param level Level at which to log the message
405406
* @param msg the message to log
406407
*/
407408
public void log(Level level, String msg) {
@@ -416,7 +417,7 @@ public void log(Level level, String msg) {
416417
* param or an Object array, and is backward-compatible with them. Calling the per-Level methods
417418
* is preferred, but this is present for completeness.
418419
*
419-
* @param level Level at which log log the message
420+
* @param level Level at which to log the message
420421
* @param msg the message to log
421422
* @param params varargs list of objects to include in the log message
422423
* @see Logger#log(java.util.logging.Level, String, Object[])
@@ -432,7 +433,7 @@ public void log(Level level, String msg, Object... params) {
432433
* Logs a message which accompanies a Throwable. Calling equivalent per-Level method is preferred,
433434
* but this is present for completeness.
434435
*
435-
* @param level Level at which log log the message
436+
* @param level Level at which to log the message
436437
* @param msg the message to log
437438
* @param thrown an Exception to include in the logged message
438439
*/

common/src/main/java/oracle/kubernetes/common/logging/BaseLoggingFormatter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public abstract class BaseLoggingFormatter<T> extends Formatter {
4242

4343
@Override
4444
public String format(LogRecord logRecord) {
45-
String sourceClassName = "";
45+
String sourceClassName;
4646
String sourceMethodName = "";
4747
if (logRecord.getSourceClassName() != null) {
4848
sourceClassName = logRecord.getSourceClassName();
@@ -71,7 +71,7 @@ public String format(LogRecord logRecord) {
7171
long rawTime = logRecord.getMillis();
7272
final String dateString = DATE_FORMAT.format(OffsetDateTime.ofInstant(logRecord.getInstant(),
7373
ZoneId.systemDefault()));
74-
long thread = Thread.currentThread().getId();
74+
long thread = Thread.currentThread().threadId();
7575
T fiberObject = getCurrentFiberIfSet();
7676

7777
map.put(TIMESTAMP, dateString);
@@ -90,7 +90,7 @@ public String format(LogRecord logRecord) {
9090
map.put(RESPONSE_CODE, code);
9191
map.put(RESPONSE_HEADERS, headers);
9292
map.put(RESPONSE_BODY, body.replace("\n", "\\\n"));
93-
String json = "";
93+
String json;
9494
try {
9595
ObjectMapper mapper = new ObjectMapper();
9696
json = mapper.writeValueAsString(map);
@@ -123,7 +123,7 @@ protected T getCurrentFiberIfSet() {
123123
protected abstract void processThrowable(LogRecord logRecord, ThrowableProcessing throwableProcessing);
124124

125125
protected class ThrowableProcessing {
126-
private LogRecord logRecord;
126+
private final LogRecord logRecord;
127127
private String code;
128128
private Map<String, List<String>> headers;
129129
private String body;

common/src/main/java/oracle/kubernetes/common/logging/LoggingFilter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.common.logging;
@@ -14,7 +14,7 @@ public interface LoggingFilter {
1414
*
1515
* @param loggingFilter LoggingFilter that decides whether the log message should be logged, can
1616
* be null
17-
* @param msg The log message to be loggd
17+
* @param msg The log message to be logged
1818
* @return the canLog() return value from the provided loggingFilter, message, and parameters, or
1919
* true if loggingFilter is null
2020
*/
@@ -26,7 +26,7 @@ static boolean canLog(LoggingFilter loggingFilter, String msg) {
2626
* Checks if the message should be logged.
2727
*
2828
* @param msg the message to be logged
29-
* @return true, if can log
29+
* @return true, if the can log
3030
*/
3131
boolean canLog(String msg);
3232
}

common/src/main/java/oracle/kubernetes/common/logging/MessageKeys.java

-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ public class MessageKeys {
1414
public static final String ENABLED_FEATURES = "WLSKO-0003";
1515
public static final String OPERATOR_SHUTTING_DOWN = "WLSKO-0005";
1616
public static final String EXCEPTION = "WLSKO-0006";
17-
public static final String NO_FORMATTING = "WLSKO-0007";
1817
public static final String CREATING_CRD = "WLSKO-0012";
1918
public static final String SECRET_NOT_FOUND = "WLSKO-0018";
2019
public static final String RETRIEVING_SECRET = "WLSKO-0019";
2120
public static final String SECRET_DATA_NOT_FOUND = "WLSKO-0020";
22-
public static final String WLS_CONFIGURATION_READ = "WLSKO-0021";
23-
public static final String JSON_PARSING_FAILED = "WLSKO-0026";
2421
public static final String NO_WLS_SERVER_IN_CLUSTER = "WLSKO-0028";
2522
public static final String VERIFY_ACCESS_START = "WLSKO-0029";
2623
public static final String VERIFY_ACCESS_DENIED = "WLSKO-0030";
@@ -89,7 +86,6 @@ public class MessageKeys {
8986
public static final String ADMIN_POD_PATCHED = "WLSKO-0120";
9087
public static final String MANAGED_POD_PATCHED = "WLSKO-0121";
9188
public static final String POD_DELETED = "WLSKO-0122";
92-
public static final String TUNING_PARAMETERS = "WLSKO-0126";
9389
public static final String WLS_HEALTH_READ_FAILED = "WLSKO-0127";
9490
public static final String WLS_SERVER_TEMPLATE_NOT_FOUND = "WLSKO-0133";
9591
public static final String SCRIPT_LOADED = "WLSKO-0134";
@@ -101,7 +97,6 @@ public class MessageKeys {
10197
public static final String CANNOT_PARSE_TOPOLOGY = "WLSKO-0141";
10298
public static final String CANNOT_PARSE_INTROSPECTOR_RESULT = "WLSKO-0142";
10399
public static final String CANNOT_PARSE_INTROSPECTOR_FILE = "WLSKO-0143";
104-
public static final String CANNOT_START_DOMAIN_AFTER_MAX_RETRIES = "WLSKO-0144";
105100
public static final String CYCLING_POD = "WLSKO-0145";
106101
public static final String REPLICAS_EXCEEDS_TOTAL_CLUSTER_SERVER_COUNT = "WLSKO-0146";
107102
public static final String POD_DUMP = "WLSKO-0148";

common/src/main/java/oracle/kubernetes/common/utils/CommonUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class CommonUtils {
1616

17-
private static CheckedFunction<String, String> getMD5Hash = CommonUtils::getMD5Hash;
17+
private static final CheckedFunction<String, String> getMD5Hash = CommonUtils::getMD5Hash;
1818

1919
public static final int MAX_ALLOWED_VOLUME_NAME_LENGTH = 63;
2020
public static final String VOLUME_NAME_SUFFIX = "-volume";
@@ -78,7 +78,7 @@ private static String getShortName(String resourceName) throws NoSuchAlgorithmEx
7878
* Gets the MD5 hash of a string.
7979
*
8080
* @param data input string
81-
* @return MD5 hash value of the data, null in case of an exception.
81+
* @return MD5 hash value of the data
8282
*/
8383
public static String getMD5Hash(String data) throws NoSuchAlgorithmException {
8484
return bytesToHex(MessageDigest.getInstance("MD5").digest(data.getBytes(StandardCharsets.UTF_8)));

common/src/main/java/oracle/kubernetes/common/utils/SchemaConversionUtils.java

+7-20
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,7 @@ public interface ResourceLookup {
116116
List<Map<String, Object>> listClusters();
117117
}
118118

119-
public static class Resources {
120-
public final Map<String, Object> domain;
121-
public final List<Map<String, Object>> clusters;
122-
123-
public Resources(Map<String, Object> domain, List<Map<String, Object>> clusters) {
124-
this.domain = domain;
125-
this.clusters = clusters;
126-
}
119+
public record Resources(Map<String, Object> domain, List<Map<String, Object>> clusters) {
127120
}
128121

129122
/**
@@ -164,7 +157,7 @@ public Resources convertDomainSchema(Map<String, Object> domain, ResourceLookup
164157
}
165158

166159
restore(PRESERVED_V8, domain);
167-
restore(PRESERVED_AUX, domain, this::validateRestoreLegacyAuxilaryImages);
160+
restore(PRESERVED_AUX, domain, this::validateRestoreLegacyAuxiliaryImages);
168161
removeAddedAdminChannelPortForwardingEnabled(domain);
169162
} else {
170163
restore(PRESERVED_V9, domain);
@@ -513,13 +506,7 @@ private static Object convertWithMap(Map<String, String> map, Object value) {
513506
}
514507

515508
private Map<String, String> select(Map<String, String> apiVersion9, Map<String, String> apiVersion8) {
516-
switch (targetAPIVersion) {
517-
case API_VERSION_V8:
518-
return apiVersion8;
519-
case API_VERSION_V9:
520-
default:
521-
return apiVersion9;
522-
}
509+
return targetAPIVersion.equals(API_VERSION_V8) ? apiVersion8 : apiVersion9;
523510
}
524511

525512
private static final Map<String, String> serverStartPolicyMap = Map.of(
@@ -578,7 +565,7 @@ Map<String, Object> getMetadata(Map<String, Object> domain) {
578565
}
579566

580567
@SuppressWarnings("unchecked")
581-
private boolean validateRestoreLegacyAuxilaryImages(Map<String, Object> domain,
568+
private boolean validateRestoreLegacyAuxiliaryImages(Map<String, Object> domain,
582569
Map<String, Object> scope, Map<String, Object> value) {
583570
List<Object> auxiliaryImages = (List<Object>) value.get(AUXILIARY_IMAGES);
584571
if (auxiliaryImages != null) {
@@ -638,10 +625,10 @@ private void addAuxiliaryImageEnv(List<Object> auxiliaryImages, Map<String, Obje
638625
private String getAuxiliaryImagePaths(List<Object> auxiliaryImages,
639626
List<Object> auxiliaryImageVolumes) {
640627
return Optional.ofNullable(auxiliaryImages).map(
641-
aiList -> createauxiliaryImagePathsEnv(aiList, auxiliaryImageVolumes)).orElse(null);
628+
aiList -> createAuxiliaryImagePathsEnv(aiList, auxiliaryImageVolumes)).orElse(null);
642629
}
643630

644-
private String createauxiliaryImagePathsEnv(List<Object> auxiliaryImages, List<Object> auxiliaryImageVolumes) {
631+
private String createAuxiliaryImagePathsEnv(List<Object> auxiliaryImages, List<Object> auxiliaryImageVolumes) {
645632
StringJoiner auxiliaryImagePaths = new StringJoiner(",","","");
646633
auxiliaryImages.forEach(auxiliaryImage -> auxiliaryImagePaths.add(
647634
getMountPath((Map<String,Object>)auxiliaryImage, auxiliaryImageVolumes)));
@@ -815,7 +802,7 @@ private void removeAndPreserveConditionsV9(Map<String, Object> status, Map<Strin
815802
return false;
816803
}
817804
return true;
818-
}).collect(Collectors.toList());
805+
}).toList();
819806
if (filteredConditions.isEmpty()) {
820807
status.remove(CONDITIONS);
821808
} else {

common/src/test/java/oracle/kubernetes/common/logging/CommonLoggingFacadeTest.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.common.logging;
@@ -421,10 +421,7 @@ public void setLevel(Level level) {
421421

422422
public boolean isLoggable(Level level) {
423423
int levelValue = this.level.intValue();
424-
if (level.intValue() < levelValue || levelValue == Level.OFF.intValue()) {
425-
return false;
426-
}
427-
return true;
424+
return level.intValue() >= levelValue && levelValue != Level.OFF.intValue();
428425
}
429426

430427
@Override

common/src/test/java/oracle/kubernetes/common/logging/OncePerMessageLoggingFilterTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// Copyright (c) 2019, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.common.logging;
55

6-
import oracle.kubernetes.common.logging.OncePerMessageLoggingFilter;
76
import org.junit.jupiter.api.Test;
87

98
import static org.hamcrest.MatcherAssert.assertThat;

0 commit comments

Comments
 (0)