brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject brooklyn-server git commit: BROOKLYN-537: fix NPE listing catalog items
Date Thu, 21 Sep 2017 15:45:40 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/0.12.0 216fe7f33 -> 4268b0161


BROOKLYN-537: fix NPE listing catalog items

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/4268b016
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/4268b016
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/4268b016

Branch: refs/heads/0.12.0
Commit: 4268b016191f3a5f049a2c9baa0e1befb8defc22
Parents: 216fe7f
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Sep 21 09:51:25 2017 +0100
Committer: Duncan Godwin <drigodwin@googlemail.com>
Committed: Thu Sep 21 16:44:30 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/api/typereg/RegisteredType.java    |  5 ++++-
 .../core/typereg/BasicBrooklynTypeRegistry.java | 20 ++++++++++----------
 .../typereg/BasicTypeImplementationPlan.java    |  4 +++-
 .../typereg/RegisteredTypeLoadingContexts.java  |  6 ++++--
 4 files changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4268b016/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java b/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
index b7158e2..fddcde3 100644
--- a/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
+++ b/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
@@ -21,6 +21,8 @@ package org.apache.brooklyn.api.typereg;
 import java.util.Collection;
 import java.util.Set;
 
+import javax.annotation.Nullable;
+
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.objs.BrooklynObject;
@@ -112,9 +114,10 @@ public interface RegisteredType extends Identifiable {
          * this may be null if the relevant transformer was not declared when created,
          * but in general we should look to determine the kind as early as possible 
          * and use that to retrieve the appropriate such transformer */
+        @Nullable 
         String getPlanFormat();
         /** data for the implementation; may be more specific */
-        Object getPlanData();
+        Object getPlanData(); // TODO unclear if this is allowed to return null; most (?)
usages do a null check
         
         @Override boolean equals(Object obj);
         @Override int hashCode();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4268b016/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index 983403c..565e3f0 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -193,13 +193,13 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
     }
 
     @Override
-    public <SpecT extends AbstractBrooklynObjectSpec<?,?>> SpecT createSpec(RegisteredType
type, @Nullable RegisteredTypeLoadingContext constraint, Class<SpecT> specSuperType)
{
+    public <SpecT extends AbstractBrooklynObjectSpec<?,?>> SpecT createSpec(RegisteredType
type, @Nullable RegisteredTypeLoadingContext constraint, @Nullable Class<SpecT> specSuperType)
{
         Preconditions.checkNotNull(type, "type");
         if (type.getKind()==RegisteredTypeKind.SPEC) {
             return createSpec(type, type.getPlan(), type.getSymbolicName(), type.getVersion(),
type.getSuperTypes(), constraint, specSuperType);
             
         } else if (type.getKind()==RegisteredTypeKind.UNRESOLVED) {
-            if (constraint.getAlreadyEncounteredTypes().contains(type.getSymbolicName()))
{
+            if (constraint != null && constraint.getAlreadyEncounteredTypes().contains(type.getSymbolicName()))
{
                 throw new UnsupportedTypePlanException("Cannot create spec from type "+type+"
(kind "+type.getKind()+"), recursive reference following "+constraint.getAlreadyEncounteredTypes());
                 
             } else {
@@ -225,13 +225,13 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
             RegisteredType type,
             TypeImplementationPlan plan,
             @Nullable String symbolicName, @Nullable String version, Set<Object> superTypes,
-            @Nullable RegisteredTypeLoadingContext constraint, Class<SpecT> specSuperType)
{
+            @Nullable RegisteredTypeLoadingContext constraint, @Nullable Class<SpecT>
specSuperType) {
         // TODO type is only used to call to "transform"; we should perhaps change transform
so it doesn't need the type?
         if (constraint!=null) {
             if (constraint.getExpectedKind()!=null && constraint.getExpectedKind()!=RegisteredTypeKind.SPEC)
{
                 throw new IllegalStateException("Cannot create spec with constraint "+constraint);
             }
-            if (constraint.getAlreadyEncounteredTypes().contains(symbolicName)) {
+            if (symbolicName != null && constraint.getAlreadyEncounteredTypes().contains(symbolicName))
{
                 // avoid recursive cycle
                 // TODO implement using java if permitted
             }
@@ -254,7 +254,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
             }
             item = CatalogItemBuilder.newItem(ciType, 
                     symbolicName!=null ? symbolicName : Identifiers.makeRandomId(8), 
-                        version!=null ? version : BasicBrooklynCatalog.DEFAULT_VERSION)
+                    version!=null ? version : BasicBrooklynCatalog.DEFAULT_VERSION)
                 .plan((String)plan.getPlanData())
                 .build();
         }
@@ -284,13 +284,13 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
     }
 
     @Override
-    public <SpecT extends AbstractBrooklynObjectSpec<?, ?>> SpecT createSpecFromPlan(String
planFormat, Object planData, RegisteredTypeLoadingContext optionalConstraint, Class<SpecT>
optionalSpecSuperType) {
+    public <SpecT extends AbstractBrooklynObjectSpec<?, ?>> SpecT createSpecFromPlan(@Nullable
String planFormat, Object planData, @Nullable RegisteredTypeLoadingContext optionalConstraint,
@Nullable Class<SpecT> optionalSpecSuperType) {
         return createSpec(RegisteredTypes.anonymousRegisteredType(RegisteredTypeKind.SPEC,
new BasicTypeImplementationPlan(planFormat, planData)),
             optionalConstraint, optionalSpecSuperType);
     }
 
     @Override
-    public <T> T createBean(RegisteredType type, RegisteredTypeLoadingContext constraint,
Class<T> optionalResultSuperType) {
+    public <T> T createBean(RegisteredType type, @Nullable RegisteredTypeLoadingContext
constraint, @Nullable Class<T> optionalResultSuperType) {
         Preconditions.checkNotNull(type, "type");
         if (type.getKind()!=RegisteredTypeKind.BEAN) { 
             if (type.getKind()==RegisteredTypeKind.UNRESOLVED) throw new ReferencedUnresolvedTypeException(type);
@@ -314,13 +314,13 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
     }
 
     @Override
-    public <T> T createBeanFromPlan(String planFormat, Object planData, RegisteredTypeLoadingContext
optionalConstraint, Class<T> optionalSuperType) {
+    public <T> T createBeanFromPlan(String planFormat, Object planData, @Nullable RegisteredTypeLoadingContext
optionalConstraint, @Nullable Class<T> optionalSuperType) {
         return createBean(RegisteredTypes.anonymousRegisteredType(RegisteredTypeKind.BEAN,
new BasicTypeImplementationPlan(planFormat, planData)),
             optionalConstraint, optionalSuperType);
     }
     
     @Override
-    public <T> T create(RegisteredType type, RegisteredTypeLoadingContext constraint,
Class<T> optionalResultSuperType) {
+    public <T> T create(RegisteredType type, @Nullable RegisteredTypeLoadingContext
constraint, @Nullable Class<T> optionalResultSuperType) {
         Preconditions.checkNotNull(type, "type");
         return new RegisteredTypeKindVisitor<T>() { 
             @Override protected T visitBean() { return createBean(type, constraint, optionalResultSuperType);
}
@@ -349,7 +349,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
     }
 
     @Override
-    public <T> T createFromPlan(Class<T> requiredSuperTypeHint, String planFormat,
Object planData, RegisteredTypeLoadingContext optionalConstraint) {
+    public <T> T createFromPlan(Class<T> requiredSuperTypeHint, @Nullable String
planFormat, Object planData, @Nullable RegisteredTypeLoadingContext optionalConstraint) {
         if (AbstractBrooklynObjectSpec.class.isAssignableFrom(requiredSuperTypeHint)) {
             @SuppressWarnings({ "unchecked", "rawtypes" })
             T result = (T) createSpecFromPlan(planFormat, planData, optionalConstraint, (Class)requiredSuperTypeHint);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4268b016/core/src/main/java/org/apache/brooklyn/core/typereg/BasicTypeImplementationPlan.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicTypeImplementationPlan.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicTypeImplementationPlan.java
index 206698f..43276bc 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicTypeImplementationPlan.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicTypeImplementationPlan.java
@@ -18,6 +18,8 @@
  */
 package org.apache.brooklyn.core.typereg;
 
+import javax.annotation.Nullable;
+
 import org.apache.brooklyn.api.typereg.RegisteredType.TypeImplementationPlan;
 
 import com.google.common.base.Objects;
@@ -26,7 +28,7 @@ public class BasicTypeImplementationPlan implements TypeImplementationPlan
{
     final String format;
     final Object data;
     
-    public BasicTypeImplementationPlan(String format, Object data) {
+    public BasicTypeImplementationPlan(@Nullable String format, Object data) {
         this.format = format;
         this.data = data;
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4268b016/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeLoadingContexts.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeLoadingContexts.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeLoadingContexts.java
index f6ee347..7eab626 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeLoadingContexts.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeLoadingContexts.java
@@ -175,8 +175,10 @@ public class RegisteredTypeLoadingContexts {
     }
         
     /** given a spec, returns the class of the item it targets, for instance returns {@link
Entity} given {@link EntitySpec};
-     * see also {@link #lookupSpecTypeForTarget(Class)} */
-    static <T extends AbstractBrooklynObjectSpec<?,?>> Class<? extends BrooklynObject>
lookupTargetTypeForSpec(Class<T> specSuperType) {
+     * see also {@link #lookupSpecTypeForTarget(Class)},
+     * If given null, returns {@link BrooklynObject}
+     */
+    static <T extends AbstractBrooklynObjectSpec<?,?>> Class<? extends BrooklynObject>
lookupTargetTypeForSpec(@Nullable Class<T> specSuperType) {
         if (specSuperType==null) return BrooklynObject.class;
         BrooklynObjectType best = null;
 


Mime
View raw message