diff --git a/jme3-core/src/main/java/com/jme3/collision/CollisionResults.java b/jme3-core/src/main/java/com/jme3/collision/CollisionResults.java
index 7f714fdb6..087e143d7 100644
--- a/jme3-core/src/main/java/com/jme3/collision/CollisionResults.java
+++ b/jme3-core/src/main/java/com/jme3/collision/CollisionResults.java
@@ -34,6 +34,7 @@ package com.jme3.collision;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
/**
* CollisionResults
is a collection returned as a result of a
@@ -43,14 +44,16 @@ import java.util.Iterator;
*/
public class CollisionResults implements Iterable {
- private final ArrayList results = new ArrayList();
+ private ArrayList results = null;
private boolean sorted = true;
/**
* Clears all collision results added to this list
*/
public void clear(){
- results.clear();
+ if (results != null) {
+ results.clear();
+ }
}
/**
@@ -59,6 +62,11 @@ public class CollisionResults implements Iterable {
* @return the iterator
*/
public Iterator iterator() {
+ if (results == null) {
+ List dumbCompiler = Collections.emptyList();
+ return dumbCompiler.iterator();
+ }
+
if (!sorted){
Collections.sort(results);
sorted = true;
@@ -68,16 +76,22 @@ public class CollisionResults implements Iterable {
}
public void addCollision(CollisionResult result){
+ if (results == null) {
+ results = new ArrayList();
+ }
results.add(result);
sorted = false;
}
public int size(){
+ if (results == null) {
+ return 0;
+ }
return results.size();
}
public CollisionResult getClosestCollision(){
- if (size() == 0)
+ if (results == null || size() == 0)
return null;
if (!sorted){
@@ -89,7 +103,7 @@ public class CollisionResults implements Iterable {
}
public CollisionResult getFarthestCollision(){
- if (size() == 0)
+ if (results == null || size() == 0)
return null;
if (!sorted){
@@ -101,6 +115,10 @@ public class CollisionResults implements Iterable {
}
public CollisionResult getCollision(int index){
+ if (results == null) {
+ throw new IndexOutOfBoundsException("Index: " + index + ", Size: 0");
+ }
+
if (!sorted){
Collections.sort(results);
sorted = true;
@@ -115,6 +133,9 @@ public class CollisionResults implements Iterable {
* @return
*/
public CollisionResult getCollisionDirect(int index){
+ if (results == null) {
+ throw new IndexOutOfBoundsException("Index: " + index + ", Size: 0");
+ }
return results.get(index);
}
@@ -122,11 +143,13 @@ public class CollisionResults implements Iterable {
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append("CollisionResults[");
- for (CollisionResult result : results){
- sb.append(result).append(", ");
- }
- if (results.size() > 0)
- sb.setLength(sb.length()-2);
+ if (results != null) {
+ for (CollisionResult result : results){
+ sb.append(result).append(", ");
+ }
+ if (results.size() > 0)
+ sb.setLength(sb.length()-2);
+ }
sb.append("]");
return sb.toString();