Author: sergiykarpenko
Date: 2010-04-02 05:16:53 -0400 (Fri, 02 Apr 2010)
New Revision: 2213
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestNullACL.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessControlList.java
Log:
EXOJCR-621: NullPointerException avoided in equal() and dump() methods
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessControlList.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessControlList.java 2010-04-02
08:42:29 UTC (rev 2212)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessControlList.java 2010-04-02
09:16:53 UTC (rev 2213)
@@ -184,18 +184,55 @@
if (obj instanceof AccessControlList)
{
AccessControlList another = (AccessControlList)obj;
- return dump().equals(another.dump());
+
+ // check owners, it may be null
+ if (!((owner == null && another.owner == null) || (owner != null
&& owner.equals(another.owner))))
+ {
+ return false;
+ }
+
+ // check accessList
+ List<AccessControlEntry> anotherAccessList = another.accessList;
+ if (accessList == null && anotherAccessList == null)
+ {
+ return true;
+ }
+ else if (accessList != null && anotherAccessList != null &&
accessList.size() == anotherAccessList.size())
+ {
+ // check content of both accessLists
+ for (int i = 0; i < accessList.size(); i++)
+ {
+ if
(!accessList.get(i).getAsString().equals(anotherAccessList.get(i).getAsString()))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+
+ //return dump().equals(another.dump());
}
return false;
}
public String dump()
{
- String res = "OWNER: " + owner + "\n";
- for (AccessControlEntry a : accessList)
+ String res = "OWNER: " + (owner != null ? owner : "null") +
"\n";
+ if (accessList != null)
{
- res += a.getAsString() + "\n";
+ for (AccessControlEntry a : accessList)
+ {
+ res += a.getAsString() + "\n";
+ }
}
+ else
+ {
+ res += "null";
+ }
return res;
}
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestNullACL.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestNullACL.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/TestNullACL.java 2010-04-02
09:16:53 UTC (rev 2213)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.usecases;
+
+import org.exoplatform.services.jcr.access.AccessControlList;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestNullACL.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestNullACL extends BaseUsecasesTest
+{
+
+ public void testNullsInACL() throws Exception
+ {
+
+ AccessControlList one = new AccessControlList(null, null);
+ AccessControlList second = new AccessControlList();
+
+ assertFalse(one.equals(second));
+ assertFalse(second.equals(one));
+
+ AccessControlList third = new AccessControlList(null, null);
+ assertTrue(one.equals(third));
+
+ // just run dumps to check for not Exceptions here
+ one.dump();
+
+ second.dump();
+ }
+}