Skip to content

Commit 4fbe0d5

Browse files
committed
Various findbugs related fixes.
1 parent 323a510 commit 4fbe0d5

File tree

23 files changed

+41
-32
lines changed

23 files changed

+41
-32
lines changed

config/findbugs/findbugs-exclude.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
<!-- Ignore this, as it is reported incorrectly from try-with-resources (will be fixed in future versions of findbugs -->
1919
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"/>
2020
</Match>
21+
<Match>
22+
<Package name="~org\.terasology\.protobuf.*" />
23+
</Match>
2124
</FindBugsFilter>

engine/src/dev/java/org/terasology/benchmark/BenchmarkResult.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ public static enum Alignment {
4343
LEFT {
4444
@Override
4545
public String pad(String value, int size) {
46-
String result = (value == null ? "" : value);
47-
while (result.length() < size) {
48-
result = result + " ";
46+
StringBuilder builder = new StringBuilder();
47+
builder.append(value == null ? "" : value);
48+
while (builder.length() < size) {
49+
builder.append(" ");
4950
}
50-
return result;
51+
return builder.toString();
5152
}
5253
},
5354

engine/src/main/java/org/terasology/engine/GameThread.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
public final class GameThread {
3636

37-
private static Thread gameThread;
37+
private static volatile Thread gameThread;
3838
private static BlockingDeque<Runnable> pendingRunnables = Queues.newLinkedBlockingDeque();
3939

4040
private GameThread() {

engine/src/main/java/org/terasology/engine/module/ModuleManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ public boolean accept(Path entry) throws IOException {
244244
logger.error("Failed to cloase allModuleClassLoader", e);
245245
}
246246
}
247+
247248
allModuleClassLoader = new ModuleClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader(), moduleSecurityManager);
248249
for (ExtensionModule module : getExtensionModules()) {
249250
module.setInactiveClassLoader(allModuleClassLoader);

engine/src/main/java/org/terasology/entitySystem/event/internal/EventSystemImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ private interface EventHandlerInfo {
392392
Object getHandler();
393393
}
394394

395-
private class ReflectedEventHandlerInfo implements EventHandlerInfo {
395+
private static class ReflectedEventHandlerInfo implements EventHandlerInfo {
396396
private ComponentSystem handler;
397397
private Method method;
398398
private ImmutableList<Class<? extends Component>> filterComponents;
@@ -448,7 +448,7 @@ public ComponentSystem getHandler() {
448448
}
449449
}
450450

451-
private class ReceiverEventHandlerInfo<T extends Event> implements EventHandlerInfo {
451+
private static class ReceiverEventHandlerInfo<T extends Event> implements EventHandlerInfo {
452452
private EventReceiver<T> receiver;
453453
private Class<? extends Component>[] components;
454454
private int priority;

engine/src/main/java/org/terasology/logic/characters/KinematicCharacterMover.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ private void walk(final CharacterMovementComponent movementComp, final Character
726726
/**
727727
* Holds the result of movement.
728728
*/
729-
public class MoveResult {
729+
public static class MoveResult {
730730

731731
private Vector3f finalPosition;
732732
private boolean horizontalHit;

engine/src/main/java/org/terasology/logic/console/ui/ConsoleTabCompletionEngine.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public String apply(CommandInfo input) {
5656
} else if (matches.size() > 1) {
5757
//multiple matches found
5858
//add list of available commands
59-
String commandMatches = "";
59+
StringBuilder commandMatches = new StringBuilder();
6060
for (String cmd : matches) {
61-
if (!commandMatches.isEmpty()) {
62-
commandMatches += " ";
61+
if (commandMatches.length() != 0) {
62+
commandMatches.append(" ");
6363
}
6464

65-
commandMatches += cmd;
65+
commandMatches.append(cmd);
6666
}
67-
console.addMessage(commandMatches);
67+
console.addMessage(commandMatches.toString());
6868
}
6969
return text;
7070
}

engine/src/main/java/org/terasology/logic/delay/DelayedActionSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void addDelayedAction(AddDelayedActionEvent event, EntityRef entity) {
9595
entity.saveComponent(delayedComponent);
9696
}
9797

98-
private final class DelayedOperation {
98+
private static final class DelayedOperation {
9999
private String operationId;
100100
private EntityRef entityRef;
101101

engine/src/main/java/org/terasology/math/TeraMath.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public static int clamp(int value, int min, int max) {
164164
* @return
165165
*/
166166
public static boolean isFinite(float value) {
167-
return value != Float.NaN && value != Float.NEGATIVE_INFINITY && value != Float.POSITIVE_INFINITY;
167+
return !Float.isNaN(value) && !Float.isInfinite(value);
168168
}
169169

170170
/**
@@ -174,7 +174,7 @@ public static boolean isFinite(float value) {
174174
* @return
175175
*/
176176
public static boolean isFinite(double value) {
177-
return value != Double.NaN && value != Double.NEGATIVE_INFINITY && value != Double.POSITIVE_INFINITY;
177+
return !Double.isNaN(value) && !Double.isInfinite(value);
178178
}
179179

180180
/**

engine/src/main/java/org/terasology/persistence/internal/GlobalStoreLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void loadMissingPrefabs(EntityData.GlobalStore globalStore) {
126126
private Prefab loadPrefab(EntityData.Prefab prefabData, Map<String, EntityData.Prefab> pendingPrefabs) {
127127
Prefab result = Assets.getPrefab(prefabData.getName());
128128
if (result == null) {
129-
if (prefabData.hasParentName() && pendingPrefabs.containsKey(pendingPrefabs.get(prefabData.getParentName()))) {
129+
if (prefabData.hasParentName() && pendingPrefabs.containsKey(prefabData.getParentName())) {
130130
loadPrefab(pendingPrefabs.get(prefabData.getParentName()), pendingPrefabs);
131131
}
132132
Module module = moduleManager.getActiveModule(new SimpleUri(prefabData.getName()).getNormalisedModuleName());

0 commit comments

Comments
 (0)