Skip to content

Commit a7aeb6d

Browse files
committed
GH-1964: Sonar Fixes
1 parent 0ba3e16 commit a7aeb6d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

spring-kafka/src/main/java/org/springframework/kafka/support/serializer/DelegatingByTopicSerialization.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
*/
4242
public abstract class DelegatingByTopicSerialization<T extends Closeable> implements Closeable {
4343

44+
private static final String UNCHECKED = "unchecked";
45+
4446
private static final LogAccessor LOGGER = new LogAccessor(DelegatingDeserializer.class);
4547

4648
/**
@@ -74,7 +76,7 @@ public abstract class DelegatingByTopicSerialization<T extends Closeable> implem
7476

7577
private T defaultDelegate;
7678

77-
protected boolean forKeys;
79+
private boolean forKeys;
7880

7981
private boolean cased = true;
8082

@@ -94,7 +96,7 @@ public void setCaseSensitive(boolean caseSensitive) {
9496
this.cased = caseSensitive;
9597
}
9698

97-
@SuppressWarnings("unchecked")
99+
@SuppressWarnings(UNCHECKED)
98100
protected void configure(Map<String, ?> configs, boolean isKey) {
99101
this.forKeys = isKey;
100102
Object insensitive = configs.get(CASE_SENSITIVE);
@@ -140,7 +142,7 @@ private void processMap(Map<String, ?> configs, boolean isKey, String configKey,
140142
});
141143
}
142144

143-
@SuppressWarnings("unchecked")
145+
@SuppressWarnings(UNCHECKED)
144146
protected void build(Map<String, ?> configs, boolean isKey, String configKey, Object delegate, Pattern pattern) {
145147

146148
if (isInstance(delegate)) {
@@ -159,7 +161,7 @@ else if (delegate instanceof String) {
159161
}
160162
}
161163

162-
@SuppressWarnings("unchecked")
164+
@SuppressWarnings(UNCHECKED)
163165
protected void buildDefault(Map<String, ?> configs, String configKey, boolean isKey, Object delegate) {
164166

165167
if (isInstance(delegate)) {
@@ -239,7 +241,7 @@ protected T instantiateAndConfigure(Map<String, ?> configs, boolean isKey, Map<P
239241
@Nullable Pattern pattern, Class<?> clazz) {
240242

241243
try {
242-
@SuppressWarnings("unchecked")
244+
@SuppressWarnings(UNCHECKED)
243245
T delegate = (T) clazz.getDeclaredConstructor().newInstance();
244246
configureDelegate(configs, isKey, delegate);
245247
if (pattern != null) {
@@ -266,7 +268,7 @@ public T removeDelegate(Pattern pattern) {
266268
* @param topic the topic.
267269
* @return the delegate.
268270
*/
269-
@SuppressWarnings("unchecked")
271+
@SuppressWarnings(UNCHECKED)
270272
protected T findDelegate(String topic) {
271273
T delegate = null;
272274
for (Entry<Pattern, T> entry : this.delegates.entrySet()) {

spring-kafka/src/main/java/org/springframework/kafka/support/serializer/DelegatingByTypeSerializer.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@
3535
*/
3636
public class DelegatingByTypeSerializer implements Serializer<Object> {
3737

38-
@SuppressWarnings("rawtypes")
38+
private static final String RAWTYPES = "rawtypes";
39+
40+
@SuppressWarnings(RAWTYPES)
3941
private final Map<Class<?>, Serializer> delegates = new HashMap<>();
4042

4143
/**
4244
* Construct an instance with the map of delegates.
4345
* @param delegates the delegates.
4446
*/
45-
@SuppressWarnings("rawtypes")
47+
@SuppressWarnings(RAWTYPES)
4648
public DelegatingByTypeSerializer(Map<Class<?>, Serializer> delegates) {
4749
Assert.notNull(delegates, "'delegates' cannot be null");
4850
Assert.noNullElements(delegates.values(), "Serializers in delegates map cannot be null");
@@ -55,21 +57,21 @@ public void configure(Map<String, ?> configs, boolean isKey) {
5557
this.delegates.values().forEach(del -> del.configure(configs, isKey));
5658
}
5759

58-
@SuppressWarnings({ "rawtypes", "unchecked" })
60+
@SuppressWarnings({ RAWTYPES, "unchecked" })
5961
@Override
6062
public byte[] serialize(String topic, Object data) {
6163
Serializer delegate = findDelegate(data);
6264
return delegate.serialize(topic, data);
6365
}
6466

65-
@SuppressWarnings({ "unchecked", "rawtypes" })
67+
@SuppressWarnings({ "unchecked", RAWTYPES })
6668
@Override
6769
public byte[] serialize(String topic, Headers headers, Object data) {
6870
Serializer delegate = findDelegate(data);
6971
return delegate.serialize(topic, headers, data);
7072
}
7173

72-
@SuppressWarnings("rawtypes")
74+
@SuppressWarnings(RAWTYPES)
7375
private Serializer findDelegate(Object data) {
7476
Serializer delegate = this.delegates.get(data.getClass());
7577
if (delegate == null) {

0 commit comments

Comments
 (0)