Skip to content

Commit

Permalink
GEODE-8882: Enable JetBrains NotNull Annotation (apache#5967)
Browse files Browse the repository at this point in the history
* Enable JetBrains NotNull Annotation in geode-core
* fix NPE bug introduced in fix for GEODE-8870
  • Loading branch information
Bill authored Jan 28, 2021
1 parent 010065e commit 1547f5f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 31 deletions.
6 changes: 6 additions & 0 deletions boms/geode-all-bom/src/test/resources/expected-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,12 @@
<version>2.4.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,10 @@ class DependencyConstraints implements Plugin<Project> {
dependencySet(group: 'org.springframework.session', version: '2.4.1') {
entry('spring-session-data-redis')
}

dependencySet(group: 'org.jetbrains', version: '20.1.0') {
entry('annotations')
}

}
}
1 change: 0 additions & 1 deletion geode-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies {
implementation(platform(project(':boms:geode-all-bom')))
implementation('com.fasterxml.jackson.core:jackson-databind')


// test
testImplementation('junit:junit')
testImplementation('org.assertj:assertj-core')
Expand Down
2 changes: 2 additions & 0 deletions geode-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ dependencies {
// find bugs leaks in from spring, needed to remove warnings.
compileOnly('com.google.code.findbugs:jsr305')

compileOnly('org.jetbrains:annotations')

//Jgroups is a core component of our membership system.
implementation('org.jgroups:jgroups')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.List;
import java.util.Map;

import org.jetbrains.annotations.Nullable;

import org.apache.geode.DataSerializer;
import org.apache.geode.Instantiator;
import org.apache.geode.internal.InternalDataSerializer;
Expand All @@ -34,7 +36,8 @@ public class SocketMessageWriter {
Integer.getInteger(GeodeGlossary.GEMFIRE_PREFIX + "serverToClientPingPeriod", 60000);

public void writeHandshakeMessage(DataOutputStream dos, byte type, String p_msg,
KnownVersion clientVersion, byte endpointType, int queueSize) throws IOException {
@Nullable KnownVersion clientVersion, byte endpointType, int queueSize)
throws IOException {
String msg = p_msg;

// write the message type
Expand All @@ -48,40 +51,41 @@ public void writeHandshakeMessage(DataOutputStream dos, byte type, String p_msg,
}
dos.writeUTF(msg);

// get all the instantiators.
Instantiator[] instantiators = InternalInstantiator.getInstantiators();
Map<Integer, List<String>> instantiatorMap = new HashMap<>();
if (instantiators != null && instantiators.length > 0) {
for (Instantiator instantiator : instantiators) {
List<String> instantiatorAttributes = new ArrayList<>();
instantiatorAttributes.add(instantiator.getClass().toString().substring(6));
instantiatorAttributes.add(instantiator.getInstantiatedClass().toString().substring(6));
instantiatorMap.put(instantiator.getId(), instantiatorAttributes);
if (clientVersion != null) {
// get all the instantiators.
Instantiator[] instantiators = InternalInstantiator.getInstantiators();
Map<Integer, List<String>> instantiatorMap = new HashMap<>();
if (instantiators != null && instantiators.length > 0) {
for (Instantiator instantiator : instantiators) {
List<String> instantiatorAttributes = new ArrayList<>();
instantiatorAttributes.add(instantiator.getClass().toString().substring(6));
instantiatorAttributes.add(instantiator.getInstantiatedClass().toString().substring(6));
instantiatorMap.put(instantiator.getId(), instantiatorAttributes);
}
}
}
DataSerializer.writeHashMap(instantiatorMap, dos);
DataSerializer.writeHashMap(instantiatorMap, dos);

// get all the dataserializers.
DataSerializer[] dataSerializers = InternalDataSerializer.getSerializers();
HashMap<Integer, ArrayList<String>> dsToSupportedClasses = new HashMap<>();
HashMap<Integer, String> dataSerializersMap = new HashMap<>();
if (dataSerializers != null && dataSerializers.length > 0) {
for (DataSerializer dataSerializer : dataSerializers) {
dataSerializersMap.put(dataSerializer.getId(),
dataSerializer.getClass().toString().substring(6));
ArrayList<String> supportedClassNames = new ArrayList<>();
for (Class<?> clazz : dataSerializer.getSupportedClasses()) {
supportedClassNames.add(clazz.getName());
// get all the dataserializers.
DataSerializer[] dataSerializers = InternalDataSerializer.getSerializers();
HashMap<Integer, ArrayList<String>> dsToSupportedClasses = new HashMap<>();
HashMap<Integer, String> dataSerializersMap = new HashMap<>();
if (dataSerializers != null && dataSerializers.length > 0) {
for (DataSerializer dataSerializer : dataSerializers) {
dataSerializersMap.put(dataSerializer.getId(),
dataSerializer.getClass().toString().substring(6));
ArrayList<String> supportedClassNames = new ArrayList<>();
for (Class<?> clazz : dataSerializer.getSupportedClasses()) {
supportedClassNames.add(clazz.getName());
}
dsToSupportedClasses.put(dataSerializer.getId(), supportedClassNames);
}
dsToSupportedClasses.put(dataSerializer.getId(), supportedClassNames);
}
DataSerializer.writeHashMap(dataSerializersMap, dos);
DataSerializer.writeHashMap(dsToSupportedClasses, dos);
if (clientVersion.isNotOlderThan(KnownVersion.GEODE_1_5_0)) {
dos.writeInt(CLIENT_PING_TASK_PERIOD);
}
}
DataSerializer.writeHashMap(dataSerializersMap, dos);
DataSerializer.writeHashMap(dsToSupportedClasses, dos);
if (clientVersion.isNotOlderThan(KnownVersion.GEODE_1_5_0)) {
dos.writeInt(CLIENT_PING_TASK_PERIOD);
}

dos.flush();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.apache.geode.internal.cache.tier.sockets;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import org.junit.Test;

public class SocketMessageWriterTest {

@Test
public void writeHandshakeMessageWithClientVersionNull() throws IOException {
final SocketMessageWriter writer = new SocketMessageWriter();
// can't mock DataOutputStream
final DataOutputStream outputStream = new DataOutputStream(new ByteArrayOutputStream());
writer.writeHandshakeMessage(outputStream, (byte) 1, "", null, (byte) 0, 0);
}
}

0 comments on commit 1547f5f

Please sign in to comment.