Skip to content

Commit

Permalink
[Spotbugs] Enable spotbugs in pulsar-metadata (apache#9253)
Browse files Browse the repository at this point in the history
Fixes streamnative/pulsar#1797

### Motivation

Enable spotbugs in module pulsar-metadata.
  • Loading branch information
RobertIndie authored Jan 26, 2021
1 parent 829704b commit 0223bb1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
22 changes: 22 additions & 0 deletions pulsar-metadata/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,26 @@
<artifactId>caffeine</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>${basedir}/src/test/resources/findbugsExclude.xml</excludeFilterFile>
</configuration>
<executions>
<execution>
<id>spotbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
@Data
public class GetResult {

/**
* The value of the key stored.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ private synchronized CompletableFuture<LeaderElectionState> elect() {
log.warn("Exception in state change listener", t);
}
}
return CompletableFuture.completedFuture(leaderElectionState);
}
return CompletableFuture.completedFuture(leaderElectionState);
} else {
return tryToBecomeLeader();
}
Expand Down Expand Up @@ -143,8 +143,8 @@ private synchronized CompletableFuture<LeaderElectionState> tryToBecomeLeader()
log.warn("Exception in state change listener", t);
}
}
result.complete(leaderElectionState);
}
result.complete(leaderElectionState);
}).exceptionally(ex -> {
// We fail to do the get(), so clean up the leader election fail the whole
// operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public synchronized CompletableFuture<Void> storeDelete(String path, Optional<Lo
Value value = map.get(path);
if (value == null) {
return FutureUtils.exception(new NotFoundException(""));
} else if (value != null && optExpectedVersion.isPresent() && optExpectedVersion.get() != value.version) {
} else if (optExpectedVersion.isPresent() && optExpectedVersion.get() != value.version) {
return FutureUtils.exception(new BadVersionException(""));
} else {
map.remove(path);
Expand All @@ -191,6 +191,6 @@ private static boolean isValidPath(String path) {
return false;
}

return path != "/" || !path.endsWith("/");
return !path.equals("/") || !path.endsWith("/");
}
}
26 changes: 26 additions & 0 deletions pulsar-metadata/src/test/resources/findbugsExclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
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.
-->
<FindBugsFilter>
<Match>
<Class name="org.apache.pulsar.metadata.api.GetResult" />
<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2" />
</Match>
</FindBugsFilter>

0 comments on commit 0223bb1

Please sign in to comment.