From 400c09a6331dff96076690fe3767e331ed702f73 Mon Sep 17 00:00:00 2001 From: shadowislord Date: Fri, 27 Mar 2015 21:32:52 -0400 Subject: [PATCH] jme3-core: fix minor issues pointed in static analysis --- .../main/java/com/jme3/asset/AssetConfig.java | 2 +- .../com/jme3/asset/DesktopAssetManager.java | 5 ++--- .../main/java/com/jme3/asset/ImplHandler.java | 6 +++--- .../main/java/com/jme3/light/SpotLight.java | 2 +- .../main/java/com/jme3/scene/BatchNode.java | 2 +- .../src/main/java/com/jme3/scene/Node.java | 2 +- .../jme3/scene/instancing/InstancedNode.java | 2 +- .../main/java/com/jme3/shader/DefineList.java | 2 +- .../java/com/jme3/texture/FrameBuffer.java | 7 ++++--- .../src/main/java/com/jme3/util/IntMap.java | 3 ++- .../jme3/util/TangentBinormalGenerator.java | 18 +++++++----------- .../util/blockparser/BlockLanguageParser.java | 2 +- .../java/com/jme3/audio/plugins/WAVLoader.java | 2 +- .../com/jme3/export/binary/BinaryImporter.java | 4 +--- 14 files changed, 27 insertions(+), 32 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/asset/AssetConfig.java b/jme3-core/src/main/java/com/jme3/asset/AssetConfig.java index 50b6e38af..71c4d8bb1 100644 --- a/jme3-core/src/main/java/com/jme3/asset/AssetConfig.java +++ b/jme3-core/src/main/java/com/jme3/asset/AssetConfig.java @@ -69,7 +69,7 @@ public final class AssetConfig { public static void loadText(AssetManager assetManager, URL configUrl) throws IOException{ InputStream in = configUrl.openStream(); try { - Scanner scan = new Scanner(in); + Scanner scan = new Scanner(in, "UTF-8"); scan.useLocale(Locale.US); // Fix commas / periods ?? while (scan.hasNext()){ String cmd = scan.next(); diff --git a/jme3-core/src/main/java/com/jme3/asset/DesktopAssetManager.java b/jme3-core/src/main/java/com/jme3/asset/DesktopAssetManager.java index 4364f3b60..66a6fbbdf 100644 --- a/jme3-core/src/main/java/com/jme3/asset/DesktopAssetManager.java +++ b/jme3-core/src/main/java/com/jme3/asset/DesktopAssetManager.java @@ -312,13 +312,12 @@ public class DesktopAssetManager implements AssetManager { protected T registerAndCloneSmartAsset(AssetKey key, T obj, AssetProcessor proc, AssetCache cache) { // object obj is the original asset // create an instance for user - T clone = (T) obj; if (proc == null) { throw new IllegalStateException("Asset implements " + "CloneableSmartAsset but doesn't " + "have processor to handle cloning"); } else { - clone = (T) proc.createClone(obj); + T clone = (T) proc.createClone(obj); if (cache != null && clone != obj) { cache.registerAssetClone(key, clone); } else { @@ -326,8 +325,8 @@ public class DesktopAssetManager implements AssetManager { + "CloneableSmartAsset but doesn't have cache or " + "was not cloned"); } + return clone; } - return clone; } @Override diff --git a/jme3-core/src/main/java/com/jme3/asset/ImplHandler.java b/jme3-core/src/main/java/com/jme3/asset/ImplHandler.java index 3601bc463..73e6d8df3 100644 --- a/jme3-core/src/main/java/com/jme3/asset/ImplHandler.java +++ b/jme3-core/src/main/java/com/jme3/asset/ImplHandler.java @@ -47,7 +47,7 @@ import java.util.logging.Logger; * This is done by keeping an instance of each asset loader and asset * locator object in a thread local. */ -public class ImplHandler { +final class ImplHandler { private static final Logger logger = Logger.getLogger(ImplHandler.class.getName()); @@ -75,7 +75,7 @@ public class ImplHandler { this.assetManager = assetManager; } - protected class ImplThreadLocal extends ThreadLocal { + protected static class ImplThreadLocal extends ThreadLocal { private final Class type; private final String path; @@ -83,7 +83,7 @@ public class ImplHandler { public ImplThreadLocal(Class type, String[] extensions){ this.type = type; - this.extensions = extensions; + this.extensions = extensions.clone(); this.path = null; } diff --git a/jme3-core/src/main/java/com/jme3/light/SpotLight.java b/jme3-core/src/main/java/com/jme3/light/SpotLight.java index 0499ce254..f02f76fa4 100644 --- a/jme3-core/src/main/java/com/jme3/light/SpotLight.java +++ b/jme3-core/src/main/java/com/jme3/light/SpotLight.java @@ -56,7 +56,7 @@ import java.io.IOException; * the light intensity slowly decrease between the inner cone and the outer cone. * @author Nehon */ -public class SpotLight extends Light implements Savable { +public class SpotLight extends Light { protected Vector3f position = new Vector3f(); protected Vector3f direction = new Vector3f(0,-1,0); diff --git a/jme3-core/src/main/java/com/jme3/scene/BatchNode.java b/jme3-core/src/main/java/com/jme3/scene/BatchNode.java index 8cfed4244..475cfdf71 100644 --- a/jme3-core/src/main/java/com/jme3/scene/BatchNode.java +++ b/jme3-core/src/main/java/com/jme3/scene/BatchNode.java @@ -64,7 +64,7 @@ import java.util.logging.Logger; * TODO more automagic (batch when needed in the updateLogicalState) * @author Nehon */ -public class BatchNode extends GeometryGroupNode implements Savable { +public class BatchNode extends GeometryGroupNode { private static final Logger logger = Logger.getLogger(BatchNode.class.getName()); /** diff --git a/jme3-core/src/main/java/com/jme3/scene/Node.java b/jme3-core/src/main/java/com/jme3/scene/Node.java index 816140e21..5edfa021b 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Node.java +++ b/jme3-core/src/main/java/com/jme3/scene/Node.java @@ -58,7 +58,7 @@ import java.util.logging.Logger; * @author Gregg Patton * @author Joshua Slack */ -public class Node extends Spatial implements Savable { +public class Node extends Spatial { private static final Logger logger = Logger.getLogger(Node.class.getName()); diff --git a/jme3-core/src/main/java/com/jme3/scene/instancing/InstancedNode.java b/jme3-core/src/main/java/com/jme3/scene/instancing/InstancedNode.java index b3cb26da0..554b8606a 100644 --- a/jme3-core/src/main/java/com/jme3/scene/instancing/InstancedNode.java +++ b/jme3-core/src/main/java/com/jme3/scene/instancing/InstancedNode.java @@ -57,7 +57,7 @@ public class InstancedNode extends GeometryGroupNode { setGeometryStartIndex(geom, startIndex); } - private static class InstanceTypeKey implements Cloneable { + private static final class InstanceTypeKey implements Cloneable { Mesh mesh; Material material; diff --git a/jme3-core/src/main/java/com/jme3/shader/DefineList.java b/jme3-core/src/main/java/com/jme3/shader/DefineList.java index 93d4cbeaf..dd605fc7e 100644 --- a/jme3-core/src/main/java/com/jme3/shader/DefineList.java +++ b/jme3-core/src/main/java/com/jme3/shader/DefineList.java @@ -40,7 +40,7 @@ import java.io.IOException; import java.util.Map; import java.util.TreeMap; -public class DefineList implements Savable, Cloneable { +public final class DefineList implements Savable, Cloneable { private static final String ONE = "1"; diff --git a/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java b/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java index ed053339c..bc21fd82b 100644 --- a/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java +++ b/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java @@ -72,9 +72,10 @@ import java.util.ArrayList; * @author Kirill Vainer */ public class FrameBuffer extends NativeObject { - public static int SLOT_UNDEF = -1; - public static int SLOT_DEPTH = -100; - public static int SLOT_DEPTH_STENCIL = -101; + + public static final int SLOT_UNDEF = -1; + public static final int SLOT_DEPTH = -100; + public static final int SLOT_DEPTH_STENCIL = -101; private int width = 0; private int height = 0; diff --git a/jme3-core/src/main/java/com/jme3/util/IntMap.java b/jme3-core/src/main/java/com/jme3/util/IntMap.java index fed91be06..38ffb2431 100644 --- a/jme3-core/src/main/java/com/jme3/util/IntMap.java +++ b/jme3-core/src/main/java/com/jme3/util/IntMap.java @@ -34,6 +34,7 @@ package com.jme3.util; import com.jme3.util.IntMap.Entry; import java.util.Iterator; import java.util.Map; +import java.util.NoSuchElementException; /** * Similar to a {@link Map} except that ints are used as keys. @@ -234,7 +235,7 @@ public final class IntMap implements Iterable>, Cloneable { public Entry next() { if (el >= size) - throw new IllegalStateException("No more elements!"); + throw new NoSuchElementException("No more elements!"); if (cur != null){ Entry e = cur; diff --git a/jme3-core/src/main/java/com/jme3/util/TangentBinormalGenerator.java b/jme3-core/src/main/java/com/jme3/util/TangentBinormalGenerator.java index ae82b3422..0f9aac1fc 100644 --- a/jme3-core/src/main/java/com/jme3/util/TangentBinormalGenerator.java +++ b/jme3-core/src/main/java/com/jme3/util/TangentBinormalGenerator.java @@ -274,11 +274,9 @@ public class TangentBinormalGenerator { triData.setIndex(index); triData.triangleOffset = i * 3 ; } - if (triData != null) { - vertices.get(index[0]).triangles.add(triData); - vertices.get(index[1]).triangles.add(triData); - vertices.get(index[2]).triangles.add(triData); - } + vertices.get(index[0]).triangles.add(triData); + vertices.get(index[1]).triangles.add(triData); + vertices.get(index[2]).triangles.add(triData); } return vertices; @@ -483,7 +481,7 @@ public class TangentBinormalGenerator { boolean isDegenerate = isDegenerateTriangle(v[0], v[1], v[2]); TriangleData triData = processTriangle(index, v, t); - if (triData != null && !isDegenerate) { + if (!isDegenerate) { vertices.get(index[0]).triangles.add(triData); vertices.get(index[1]).triangles.add(triData); vertices.get(index[2]).triangles.add(triData); @@ -529,11 +527,9 @@ public class TangentBinormalGenerator { populateFromBuffer(t[2], textureBuffer, index[2]); TriangleData triData = processTriangle(index, v, t); - if (triData != null) { - vertices.get(index[0]).triangles.add(triData); - vertices.get(index[1]).triangles.add(triData); - vertices.get(index[2]).triangles.add(triData); - } + vertices.get(index[0]).triangles.add(triData); + vertices.get(index[1]).triangles.add(triData); + vertices.get(index[2]).triangles.add(triData); Vector3f vTemp = v[1]; v[1] = v[2]; diff --git a/jme3-core/src/main/java/com/jme3/util/blockparser/BlockLanguageParser.java b/jme3-core/src/main/java/com/jme3/util/blockparser/BlockLanguageParser.java index 16968aad2..7718a0f4b 100644 --- a/jme3-core/src/main/java/com/jme3/util/blockparser/BlockLanguageParser.java +++ b/jme3-core/src/main/java/com/jme3/util/blockparser/BlockLanguageParser.java @@ -71,7 +71,7 @@ public class BlockLanguageParser { private void load(InputStream in) throws IOException{ reset(); - reader = new InputStreamReader(in); + reader = new InputStreamReader(in, "UTF-8"); StringBuilder buffer = new StringBuilder(); boolean insideComment = false; diff --git a/jme3-core/src/plugins/java/com/jme3/audio/plugins/WAVLoader.java b/jme3-core/src/plugins/java/com/jme3/audio/plugins/WAVLoader.java index 098de7a15..997a8f4fb 100644 --- a/jme3-core/src/plugins/java/com/jme3/audio/plugins/WAVLoader.java +++ b/jme3-core/src/plugins/java/com/jme3/audio/plugins/WAVLoader.java @@ -196,7 +196,7 @@ public class WAVLoader implements AssetLoader { break; case i_data: // Compute duration based on data chunk size - duration = len / bytesPerSec; + duration = (float)(len / bytesPerSec); if (readStream) { readDataChunkForStream(inOffset, len); diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java b/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java index 933bee721..b34adbca6 100644 --- a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java +++ b/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java @@ -270,9 +270,7 @@ public final class BinaryImporter implements JmeImporter { try { return load(fis, listener); } finally { - if (fis != null) { - fis.close(); - } + fis.close(); } }