This is an automated email from the ASF dual-hosted git repository.

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 5308c80  Additional parameter checking
     new 56aaba6  Merge pull request #98 from bosschaert/tck_fixes_2
5308c80 is described below

commit 5308c807267c74a94fdf4c5904b6dc59da5c2f01
Author: David Bosschaert <dav...@apache.org>
AuthorDate: Tue Sep 7 08:37:30 2021 +0100

    Additional parameter checking
    
    This fixes a number of TCK failures
---
 .../felix/feature/impl/ArtifactBuilderImpl.java    | 32 +++++++++++++++++-----
 .../felix/feature/impl/BundleBuilderImpl.java      | 20 +++++++++++++-
 2 files changed, 44 insertions(+), 8 deletions(-)

diff --git 
a/features/src/main/java/org/apache/felix/feature/impl/ArtifactBuilderImpl.java 
b/features/src/main/java/org/apache/felix/feature/impl/ArtifactBuilderImpl.java
index 683d914..f1c8c3f 100644
--- 
a/features/src/main/java/org/apache/felix/feature/impl/ArtifactBuilderImpl.java
+++ 
b/features/src/main/java/org/apache/felix/feature/impl/ArtifactBuilderImpl.java
@@ -39,34 +39,52 @@ class ArtifactBuilderImpl implements FeatureArtifactBuilder 
{
        if (key == null)
                throw new IllegalArgumentException("Metadata key cannot be 
null");
 
-       if (value == null)
-               throw new IllegalArgumentException("Metadata value cannot be 
null");
-       
+       if (key.length() == 0)
+               throw new IllegalArgumentException("Key must not be empty");
+
        if ("id".equalsIgnoreCase(key))
                throw new IllegalArgumentException("Key cannot be 'id'");
+       
+       checkMetadataValue(value);
                
         this.metadata.put(key, value);
         return this;
     }
 
-    @Override
+       @Override
     public FeatureArtifactBuilder addMetadata(Map<String,Object> md) {
        if (md.keySet().contains(null))
                throw new IllegalArgumentException("Metadata key cannot be 
null");
        
-       if (md.values().contains(null))
-               throw new IllegalArgumentException("Metadata value cannot be 
null");
-       
+       if (md.keySet().contains(""))
+               throw new IllegalArgumentException("Key must not be empty");
+
        if (md.keySet().stream()
                .map(String::toLowerCase)
                .anyMatch(s -> "id".equals(s))) {
                throw new IllegalArgumentException("Key cannot be 'id'");       
        
        }
+       
+       md.values().stream()
+                       .forEach(this::checkMetadataValue);
 
        this.metadata.putAll(md);
         return this;
     }
 
+    private void checkMetadataValue(Object value) {
+       if (value instanceof String) 
+               return;
+       
+       if (value instanceof Boolean)
+               return;
+       
+       if (value instanceof Number)
+               return;
+       
+       throw new IllegalArgumentException("Illegal metadata value: " + value);
+       }
+
     @Override
     public FeatureArtifact build() {
         return new ArtifactImpl(id, metadata);
diff --git 
a/features/src/main/java/org/apache/felix/feature/impl/BundleBuilderImpl.java 
b/features/src/main/java/org/apache/felix/feature/impl/BundleBuilderImpl.java
index 7232dfe..275ccb7 100644
--- 
a/features/src/main/java/org/apache/felix/feature/impl/BundleBuilderImpl.java
+++ 
b/features/src/main/java/org/apache/felix/feature/impl/BundleBuilderImpl.java
@@ -45,7 +45,9 @@ class BundleBuilderImpl implements FeatureBundleBuilder {
        if ("id".equalsIgnoreCase(key))
                throw new IllegalArgumentException("Key cannot be 'id'");
        
-        this.metadata.put(key, value);
+       checkMetadataValue(value);
+
+       this.metadata.put(key, value);
         return this;
     }
 
@@ -63,10 +65,26 @@ class BundleBuilderImpl implements FeatureBundleBuilder {
                throw new IllegalArgumentException("Key cannot be 'id'");       
        
        }
                        
+       md.values().stream()
+                       .forEach(this::checkMetadataValue);
+
         this.metadata.putAll(md);
         return this;
     }
 
+    private void checkMetadataValue(Object value) {
+       if (value instanceof String) 
+               return;
+       
+       if (value instanceof Boolean)
+               return;
+       
+       if (value instanceof Number)
+               return;
+       
+       throw new IllegalArgumentException("Illegal metadata value: " + value);
+       }
+
     @Override
     public FeatureBundle build() {
         return new BundleImpl(id, metadata);

Reply via email to