Explorar o código

resolve issue #1419 (explicitly thrown NullPointerExceptions) (#1486)

Stephen Gold %!s(int64=4) %!d(string=hai) anos
pai
achega
74f483a624

+ 1 - 1
jme3-core/src/main/java/com/jme3/material/Material.java

@@ -88,7 +88,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
 
     public Material(MaterialDef def) {
         if (def == null) {
-            throw new NullPointerException("Material definition cannot be null");
+            throw new IllegalArgumentException("Material definition cannot be null");
         }
         this.def = def;
 

+ 2 - 2
jme3-core/src/main/java/com/jme3/scene/Geometry.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2020 jMonkeyEngine
+ * Copyright (c) 2009-2021 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -303,7 +303,7 @@ public class Geometry extends Spatial {
     protected void updateWorldBound() {
         super.updateWorldBound();
         if (mesh == null) {
-            throw new NullPointerException("Geometry: " + getName() + " has null mesh");
+            throw new IllegalStateException("Geometry \"" + getName() + "\" has null mesh.");
         }
 
         if (mesh.getBound() != null) {

+ 6 - 6
jme3-core/src/main/java/com/jme3/scene/Node.java

@@ -339,7 +339,7 @@ public class Node extends Spatial {
      * @param child
      *            the child to attach to this node.
      * @return the number of children maintained by this node.
-     * @throws NullPointerException if child is null.
+     * @throws IllegalArgumentException if child is null or this
      */
     public int attachChildAt(Spatial child, int index) {
         if (child == null) {
@@ -374,12 +374,12 @@ public class Node extends Spatial {
      * This child will no longer be maintained.
      *
      * @param child
-     *            the child to remove.
+     *            the child to remove (not null)
      * @return the index the child was at. -1 if the child was not in the list.
      */
     public int detachChild(Spatial child) {
         if (child == null) {
-            throw new NullPointerException();
+            throw new IllegalArgumentException("child cannot be null");
         }
 
         if (child.getParent() == this) {
@@ -395,16 +395,16 @@ public class Node extends Spatial {
 
     /**
      * <code>detachChild</code> removes a given child from the node's list.
-     * This child will no longe be maintained. Only the first child with a
+     * This child will no longer be maintained. Only the first child with a
      * matching name is removed.
      *
      * @param childName
-     *            the child to remove.
+     *            the child to remove (not null)
      * @return the index the child was at. -1 if the child was not in the list.
      */
     public int detachChildNamed(String childName) {
         if (childName == null) {
-            throw new NullPointerException();
+            throw new IllegalArgumentException("childName cannot be null");
         }
 
         for (int x = 0, max = children.size(); x < max; x++) {

+ 2 - 2
jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java

@@ -218,11 +218,11 @@ public abstract class AbstractShadowRenderer implements SceneProcessor, Savable,
      * Sets the filtering mode for shadow edges. See {@link EdgeFilteringMode}
      * for more info.
      *
-     * @param filterMode the desired filter mode (not null)
+     * @param filterMode the desired filtering mode (not null)
      */
     final public void setEdgeFilteringMode(EdgeFilteringMode filterMode) {
         if (filterMode == null) {
-            throw new NullPointerException();
+            throw new IllegalArgumentException("filterMode cannot be null");
         }
 
         this.edgeFilteringMode = filterMode;

+ 4 - 4
jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java

@@ -258,11 +258,11 @@ public class PssmShadowRenderer implements SceneProcessor {
      * Sets the filtering mode for shadow edges see {@link FilterMode} for more
      * info
      *
-     * @param filterMode
+     * @param filterMode the desired mode (not null)
      */
     final public void setFilterMode(FilterMode filterMode) {
         if (filterMode == null) {
-            throw new NullPointerException();
+            throw new IllegalArgumentException("filterMode cannot be null");
         }
 
         if (this.filterMode == filterMode) {
@@ -289,11 +289,11 @@ public class PssmShadowRenderer implements SceneProcessor {
     /**
      * sets the shadow compare mode see {@link CompareMode} for more info
      *
-     * @param compareMode
+     * @param compareMode the desired mode (not null)
      */
     final public void setCompareMode(CompareMode compareMode) {
         if (compareMode == null) {
-            throw new NullPointerException();
+            throw new IllegalArgumentException("compareMode cannot be null");
         }
 
         if (this.compareMode == compareMode) {

+ 3 - 3
jme3-core/src/main/java/com/jme3/texture/Image.java

@@ -1037,14 +1037,14 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      * <code>setFormat</code> sets the image format for this image.
      *
      * @param format
-     *            the image format.
-     * @throws NullPointerException
+     *            the image format (not null)
+     * @throws IllegalArgumentException
      *             if format is null
      * @see Format
      */
     public void setFormat(Format format) {
         if (format == null) {
-            throw new NullPointerException("format may not be null.");
+            throw new IllegalArgumentException("format may not be null.");
         }
 
         this.format = format;

+ 3 - 2
jme3-core/src/plugins/java/com/jme3/asset/plugins/FileLocator.java

@@ -46,8 +46,9 @@ public class FileLocator implements AssetLocator {
 
     @Override
     public void setRootPath(String rootPath) {
-        if (rootPath == null)
-            throw new NullPointerException();
+        if (rootPath == null) {
+            throw new IllegalArgumentException("rootPath cannot be null");
+        }
         
         try {
             root = new File(rootPath).getCanonicalFile();

+ 5 - 5
jme3-desktop/src/main/java/com/jme3/app/SettingsDialog.java

@@ -111,13 +111,13 @@ public final class SettingsDialog extends JFrame {
      *
      * @param source
      *            the <code>AppSettings</code> object to use for working with
-     *            the properties file.
+     *            the properties file (not null)
      * @param imageFile
      *            the image file to use as the title of the dialog;
      *            <code>null</code> will result in to image being displayed
      * @param loadSettings
      *            if true, copy the settings, otherwise merge them
-     * @throws NullPointerException
+     * @throws IllegalArgumentException
      *             if the source is <code>null</code>
      */
     public SettingsDialog(AppSettings source, String imageFile, boolean loadSettings) {
@@ -130,18 +130,18 @@ public final class SettingsDialog extends JFrame {
      * 
      * @param source
      *            the <code>GameSettings</code> object to use for working with
-     *            the properties file.
+     *            the properties file (not null)
      * @param imageFile
      *            the image file to use as the title of the dialog;
      *            <code>null</code> will result in to image being displayed
      * @param loadSettings
      *            if true, copy the settings, otherwise merge them
-     * @throws NullPointerException
+     * @throws IllegalArgumentException
      *             if the source is <code>null</code>
      */
     public SettingsDialog(AppSettings source, URL imageFile, boolean loadSettings) {
         if (source == null) {
-            throw new NullPointerException("Settings source cannot be null");
+            throw new IllegalArgumentException("Settings source cannot be null");
         }
 
         this.source = source;

+ 3 - 3
jme3-desktop/src/main/java/com/jme3/system/AWTComponentRenderer.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2018 jMonkeyEngine
+ * Copyright (c) 2009-2021 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -216,7 +216,7 @@ public class AWTComponentRenderer {
 
   /**
    * Get the graphics context of the given component.
-   * @param destination the AWT component used for rendering.
+   * @param destination the AWT component used for rendering (not null)
    * @return the graphics context of the given component.
    */
   protected Graphics getGraphics(Component destination) {
@@ -230,7 +230,7 @@ public class AWTComponentRenderer {
         //throw new IllegalArgumentException("AWT component "+destination.getClass().getSimpleName()+" does not provide 2D graphics capabilities.");
       }
     } else {
-      throw new NullPointerException("Component cannot be null.");
+      throw new IllegalArgumentException("destination component cannot be null");
     }
   }
 

+ 16 - 11
jme3-niftygui/src/main/java/com/jme3/niftygui/SoundHandleJme.java

@@ -45,9 +45,12 @@ public class SoundHandleJme implements SoundHandle {
     private String fileName;
     private float volume = 1;
 
-    public SoundHandleJme(AudioRenderer ar, AudioNode node){
-        if (ar == null || node == null) {
-            throw new NullPointerException();
+    public SoundHandleJme(AudioRenderer ar, AudioNode node) {
+        if (ar == null) {
+            throw new IllegalArgumentException("AudioRenderer cannot be null");
+        }
+        if (node == null) {
+            throw new IllegalArgumentException("AudioNode cannot be null");
         }
 
         this.node = node;
@@ -56,20 +59,22 @@ public class SoundHandleJme implements SoundHandle {
     /**
      * For streaming music only. (May need to loop..)
      *
-     * @param ar for rendering audio
-     * @param am the AssetManager for loading assets
+     * @param ar for rendering audio (not null)
+     * @param am the AssetManager for loading assets (not null)
      * @param fileName the path to the audio asset (not null)
      */
-    public SoundHandleJme(AudioRenderer ar, AssetManager am, String fileName){
-        if (ar == null || am == null) {
-            throw new NullPointerException();
+    public SoundHandleJme(AudioRenderer ar, AssetManager am, String fileName) {
+        if (ar == null) {
+            throw new IllegalArgumentException("AudioRenderer cannot be null");
+        }
+        if (am == null) {
+            throw new IllegalArgumentException("AssetManager cannot be null");
         }
-
-        this.am = am;
         if (fileName == null) {
-            throw new NullPointerException();
+            throw new IllegalArgumentException("fileName cannot be null");
         }
 
+        this.am = am;
         this.fileName = fileName;
     }
 

+ 3 - 3
jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/LODGeomap.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2020 jMonkeyEngine
+ * Copyright (c) 2009-2021 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -627,7 +627,7 @@ public class LODGeomap extends GeoMap {
 
     public FloatBuffer[] writeTangentArray(FloatBuffer normalBuffer, FloatBuffer tangentStore, FloatBuffer binormalStore, FloatBuffer textureBuffer, Vector3f scale) {
         if (!isLoaded()) {
-            throw new NullPointerException();
+            throw new IllegalStateException("The Geomap data is not loaded.");
         }
 
         if (tangentStore != null) {
@@ -769,7 +769,7 @@ public class LODGeomap extends GeoMap {
     @Override
     public FloatBuffer writeNormalArray(FloatBuffer store, Vector3f scale) {
         if (!isLoaded()) {
-            throw new NullPointerException();
+            throw new IllegalStateException("The Geomap data is not loaded.");
         }
 
         if (store != null) {

+ 1 - 2
jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainQuad.java

@@ -1928,8 +1928,7 @@ public class TerrainQuad extends Node implements Terrain {
      */
     public void setSupportMultipleCollisions(boolean set) {
         if (picker == null) {
-            // This is so that it doesn't fail at the IllegalStateException because null !instanceof Anything
-            throw new NullPointerException("TerrainPicker is null");
+            throw new IllegalStateException("The TerrainPicker is null.");
         } else if (picker instanceof BresenhamTerrainPicker) {
             ((BresenhamTerrainPicker)picker).setSupportMultipleCollisions(set);
         } else {

+ 1 - 1
jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowRendererVR.java

@@ -221,7 +221,7 @@ public abstract class AbstractShadowRendererVR implements SceneProcessor, Savabl
      */
     final public void setEdgeFilteringMode(EdgeFilteringMode filterMode) {
         if (filterMode == null) {
-            throw new NullPointerException();
+            throw new IllegalArgumentException("filterMode cannot be null");
         }
 
         this.edgeFilteringMode = filterMode;