diff --git a/engine/src/main/java/org/terasology/engine/core/LoggingContext.java b/engine/src/main/java/org/terasology/engine/core/LoggingContext.java index 7ae31e0e291..ae7bf86d65e 100644 --- a/engine/src/main/java/org/terasology/engine/core/LoggingContext.java +++ b/engine/src/main/java/org/terasology/engine/core/LoggingContext.java @@ -75,7 +75,7 @@ public static void initialize(Path logFileFolder) { try { deleteLogFiles(logFileFolder, Duration.ofDays(5).getSeconds()); } catch (IOException e) { - e.printStackTrace(); + e.printStackTrace(); //NOPMD } // Unfortunately, setting context-based variables works only after initialization diff --git a/engine/src/main/java/org/terasology/engine/core/module/ModuleInstaller.java b/engine/src/main/java/org/terasology/engine/core/module/ModuleInstaller.java index 5f332ab5e54..bf27190693d 100644 --- a/engine/src/main/java/org/terasology/engine/core/module/ModuleInstaller.java +++ b/engine/src/main/java/org/terasology/engine/core/module/ModuleInstaller.java @@ -65,7 +65,7 @@ private Map getDownloadUrls(Iterable modules) { try { uri = RemoteModuleExtension.getDownloadUrl(metadata).toURI(); } catch (URISyntaxException e) { - e.printStackTrace(); + logger.error("Couldn't get download URL: ", e); } String fileName = String.format("%s-%s.jar", id, version); Path folder = PathManager.getInstance().getHomeModPath().normalize(); diff --git a/engine/src/main/java/org/terasology/engine/core/module/rendering/RenderingModuleRegistry.java b/engine/src/main/java/org/terasology/engine/core/module/rendering/RenderingModuleRegistry.java index 8400c0110dc..10bb093c09b 100644 --- a/engine/src/main/java/org/terasology/engine/core/module/rendering/RenderingModuleRegistry.java +++ b/engine/src/main/java/org/terasology/engine/core/module/rendering/RenderingModuleRegistry.java @@ -2,8 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 package org.terasology.engine.core.module.rendering; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.terasology.engine.context.Context; import org.terasology.engine.rendering.dag.ModuleRendering; +import org.terasology.engine.rendering.nui.layers.mainMenu.UniverseSetupScreen; import org.terasology.gestalt.module.ModuleEnvironment; import org.terasology.context.annotation.API; import org.terasology.gestalt.naming.Name; @@ -20,6 +23,7 @@ @API public class RenderingModuleRegistry { + private static final Logger LOGGER = LoggerFactory.getLogger(RenderingModuleRegistry.class); private List orderedModuleRenderingInstances = new ArrayList<>(); @@ -126,7 +130,7 @@ private Set fetchRenderingModules(ModuleEnvironment moduleEnvir Constructor constructor = renderingClass.getConstructor(Context.class); moduleRenderingInstance = (ModuleRendering) constructor.newInstance(context); } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); + LOGGER.error("Couldn't get constructor: ", e); } } if (moduleRenderingInstance != null) { diff --git a/engine/src/main/java/org/terasology/engine/logic/behavior/asset/GroupBuilder.java b/engine/src/main/java/org/terasology/engine/logic/behavior/asset/GroupBuilder.java index f8b455d6a89..8dc4a9d7864 100644 --- a/engine/src/main/java/org/terasology/engine/logic/behavior/asset/GroupBuilder.java +++ b/engine/src/main/java/org/terasology/engine/logic/behavior/asset/GroupBuilder.java @@ -19,6 +19,7 @@ * @see Group */ @API +@SuppressWarnings("PMD.AvoidPrintStackTrace") public class GroupBuilder { private GroupData groupData; diff --git a/engine/src/main/java/org/terasology/engine/logic/debug/MovementDebugCommands.java b/engine/src/main/java/org/terasology/engine/logic/debug/MovementDebugCommands.java index 473ce735724..9387b942bef 100644 --- a/engine/src/main/java/org/terasology/engine/logic/debug/MovementDebugCommands.java +++ b/engine/src/main/java/org/terasology/engine/logic/debug/MovementDebugCommands.java @@ -263,7 +263,7 @@ public String playerEyeHeight(@Sender EntityRef client, @CommandParam("eye-heigh } return ""; } catch (NullPointerException e) { - e.printStackTrace(); + logger.error("Couldn't set player eye height: e"); return ""; } } diff --git a/engine/src/main/java/org/terasology/engine/network/internal/ServerConnectListManager.java b/engine/src/main/java/org/terasology/engine/network/internal/ServerConnectListManager.java index 2763485aad6..6a8660de4de 100644 --- a/engine/src/main/java/org/terasology/engine/network/internal/ServerConnectListManager.java +++ b/engine/src/main/java/org/terasology/engine/network/internal/ServerConnectListManager.java @@ -69,7 +69,7 @@ private void saveLists() { whitelistWriter.close(); } } catch (IOException e) { - e.printStackTrace(); + logger.error("Couldn't save lists: ", e); } } diff --git a/engine/src/main/java/org/terasology/engine/rendering/nui/layers/mainMenu/UniverseSetupScreen.java b/engine/src/main/java/org/terasology/engine/rendering/nui/layers/mainMenu/UniverseSetupScreen.java index da5366b92d6..4ba2fcd0800 100644 --- a/engine/src/main/java/org/terasology/engine/rendering/nui/layers/mainMenu/UniverseSetupScreen.java +++ b/engine/src/main/java/org/terasology/engine/rendering/nui/layers/mainMenu/UniverseSetupScreen.java @@ -4,6 +4,8 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.terasology.engine.config.Config; import org.terasology.engine.context.Context; import org.terasology.engine.core.GameEngine; @@ -42,6 +44,7 @@ import org.terasology.engine.world.generator.internal.WorldGeneratorManager; import org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary; import org.terasology.engine.world.generator.plugin.WorldGeneratorPluginLibrary; +import org.terasology.engine.world.time.WorldTimeImpl; import org.terasology.engine.world.zones.Zone; import org.terasology.gestalt.assets.AssetType; import org.terasology.gestalt.assets.ResourceUrn; @@ -94,6 +97,8 @@ * for a particular game template. */ public class UniverseSetupScreen extends CoreScreenLayer implements UISliderOnChangeTriggeredListener, PropertyChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(UniverseSetupScreen.class); + public static final ResourceUrn ASSET_URI = new ResourceUrn("engine:universeSetupScreen"); @In @@ -354,10 +359,10 @@ private void addNewWorld(WorldGeneratorInfo worldGeneratorInfo) { } catch (UnresolvedWorldGeneratorException e) { getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Selected world generator cannot be resolved!", "Please report this issue on Discord/GitHub and select a different world generator!"); - e.printStackTrace(); + LOGGER.error("Selected world generator cannot be resolved: ", e); } catch (UnresolvedDependencyException e) { //TODO: this will likely fail at game creation time later-on due to lack of world generator - don't just ignore this - e.printStackTrace(); + LOGGER.error("Selected world generator cannot be resolved: ", e); } configureProperties(); diff --git a/facades/PC/src/main/java/org/terasology/engine/Terasology.java b/facades/PC/src/main/java/org/terasology/engine/Terasology.java index 43ca9258e33..215862b7290 100644 --- a/facades/PC/src/main/java/org/terasology/engine/Terasology.java +++ b/facades/PC/src/main/java/org/terasology/engine/Terasology.java @@ -318,7 +318,7 @@ private void populateSubsystems(TerasologyEngineBuilder builder) { builder.add(new HibernationSubsystem()); } - @SuppressWarnings("PMD.SystemPrintln") + @SuppressWarnings({"PMD.SystemPrintln", "PMD.AvoidPrintStackTrace"}) private void reportException(Throwable throwable) { Path logPath = LoggingContext.getLoggingPath();