Bug 366337 - Possible null pointer exception on ant
diff --git a/ant/org.eclipse.ant.core/src/org/eclipse/ant/core/Property.java b/ant/org.eclipse.ant.core/src/org/eclipse/ant/core/Property.java
index 2c93c92..8d7bb6d 100644
--- a/ant/org.eclipse.ant.core/src/org/eclipse/ant/core/Property.java
+++ b/ant/org.eclipse.ant.core/src/org/eclipse/ant/core/Property.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * asifrc@terpmail.umd.edu - bug 366337 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=366337)
*******************************************************************************/
package org.eclipse.ant.core;
@@ -57,7 +58,7 @@
* @see Object#equals()
*/
public boolean equals(Object other) {
- if (other.getClass().equals(getClass())) {
+ if (other != null && other.getClass().equals(getClass())) {
Property elem= (Property)other;
return name.equals(elem.getName());
}
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AutomatedSuite.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AutomatedSuite.java
index 941a499..a4cbcef 100644
--- a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AutomatedSuite.java
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AutomatedSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,6 +17,7 @@
import org.eclipse.ant.tests.core.tests.FrameworkTests;
import org.eclipse.ant.tests.core.tests.OptionTests;
import org.eclipse.ant.tests.core.tests.ProjectTests;
+import org.eclipse.ant.tests.core.tests.PropertyTests;
import org.eclipse.ant.tests.core.tests.TargetTests;
import org.eclipse.ant.tests.core.tests.TaskTests;
import org.eclipse.ant.tests.core.tests.TypeTests;
@@ -52,5 +53,6 @@
addTest(new TestSuite(OptionTests.class));
addTest(new TestSuite(TaskTests.class));
addTest(new TestSuite(TypeTests.class));
+ addTest(new TestSuite(PropertyTests.class));
}
}
\ No newline at end of file
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/PropertyTests.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/PropertyTests.java
new file mode 100644
index 0000000..380cef3
--- /dev/null
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/PropertyTests.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ant.tests.core.tests;
+
+import org.eclipse.ant.core.Property;
+import org.eclipse.ant.tests.core.AbstractAntTest;
+
+/**
+ * Tests the {@link Property} class
+ * @since 3.8
+ */
+public class PropertyTests extends AbstractAntTest {
+
+ /**
+ * Constructor
+ */
+ public PropertyTests() {
+ super("Ant property tests");
+ }
+
+ public void testPropertyEqual() throws Exception {
+ Property p1 = new Property("one", "ONE");
+ Property p2 = new Property("one", "ONE");
+ assertTrue("The properties should be equal", p1.equals(p2));
+ }
+
+ public void testPropertyEqualNameOnly() throws Exception {
+ Property p1 = new Property("two", "TWO");
+ Property p2 = new Property("two", "FOUR");
+ assertTrue("The properties should be equal", p1.equals(p2));
+ }
+
+ public void testPropertyNotEqual() throws Exception {
+ Property p1 = new Property("three", "THREE");
+ Property p2 = new Property("four", "FOUR");
+ assertFalse("The properties should not be equal", p1.equals(p2));
+ }
+
+ public void testPropertyNotEqual2() throws Exception {
+ Property p1 = new Property("five", "FIVE");
+ Property p2 = new Property("six", "FIVE");
+ assertFalse("The properties should not be equal", p1.equals(p2));
+ }
+
+ public void testPropertyNotEqualNull() throws Exception {
+ Property p1 = new Property("seven", "SEVEN");
+ assertFalse("The properties should not be equal", p1.equals(null));
+ }
+}