Quellcode durchsuchen

jme3-core: fix minor issues pointed in static analysis

shadowislord vor 10 Jahren
Ursprung
Commit
400c09a633

+ 1 - 1
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();

+ 2 - 3
jme3-core/src/main/java/com/jme3/asset/DesktopAssetManager.java

@@ -312,13 +312,12 @@ public class DesktopAssetManager implements AssetManager {
     protected <T> T registerAndCloneSmartAsset(AssetKey<T> 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

+ 3 - 3
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<T> extends ThreadLocal {
+    protected static class ImplThreadLocal<T> extends ThreadLocal {
 
         private final Class<T> type;
         private final String path;
@@ -83,7 +83,7 @@ public class ImplHandler {
 
         public ImplThreadLocal(Class<T> type, String[] extensions){
             this.type = type;
-            this.extensions = extensions;
+            this.extensions = extensions.clone();
             this.path = null;
         }
 

+ 1 - 1
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);

+ 1 - 1
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());
     /**

+ 1 - 1
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());
 

+ 1 - 1
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;

+ 1 - 1
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";
     

+ 4 - 3
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;

+ 2 - 1
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<T> implements Iterable<Entry<T>>, 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;

+ 7 - 11
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];

+ 1 - 1
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;

+ 1 - 1
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);

+ 1 - 3
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();
         }
     }