Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest API location transformers use mutable map #99

Merged
merged 1 commit into from
Apr 6, 2016

Conversation

sjcorbett
Copy link
Contributor

LocationConfig contains null values which Guava's ImmutableMap rejects with a NullPointerException.

This fixes an error observed when deploying the "Template 1: Server" sample to localhost then running br application <id> with the CLI. The output from the CLI was "500 Server Error". The server logs contained:

java.lang.NullPointerException: null value in entry: byon.machineSpecs=null
    at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:33) ~[com.google.guava-guava-16.0.1.jar:na]
    at com.google.common.collect.ImmutableMap.entryOf(ImmutableMap.java:135) ~[com.google.guava-guava-16.0.1.jar:na]
    at com.google.common.collect.ImmutableMap$Builder.put(ImmutableMap.java:206) ~[com.google.guava-guava-16.0.1.jar:na]
    at org.apache.brooklyn.rest.transform.LocationTransformer.copyConfig(LocationTransformer.java:128) ~[org.apache.brooklyn-brooklyn-rest-resources-0.10.0-SNAPSHOT.jar:0.10.0-SNAPSHOT]
    at org.apache.brooklyn.rest.transform.LocationTransformer.newInstance(LocationTransformer.java:189) ~[org.apache.brooklyn-brooklyn-rest-resources-0.10.0-SNAPSHOT.jar:0.10.0-SNAPSHOT]
    at org.apache.brooklyn.rest.resources.LocationResource.get(LocationResource.java:139) ~[org.apache.brooklyn-brooklyn-rest-resources-0.10.0-SNAPSHOT.jar:0.10.0-SNAPSHOT]
    at org.apache.brooklyn.rest.resources.LocationResource.get(LocationResource.java:132) ~[org.apache.brooklyn-brooklyn-rest-resources-0.10.0-SNAPSHOT.jar:0.10.0-SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_05]

LocationConfig contains null values which Guava's ImmutableMap rejects
with a NullPointerException
@sjcorbett
Copy link
Contributor Author

Test failure unrelated. Filed at https://issues.apache.org/jira/browse/BROOKLYN-247. Trying again.

@sjcorbett sjcorbett closed this Apr 5, 2016
@sjcorbett sjcorbett reopened this Apr 5, 2016
@@ -53,7 +54,7 @@ public LocationSpec(
@JsonProperty("config") @Nullable Map<String, ?> config) {
this.name = name;
this.spec = spec;
this.config = (config == null) ? Collections.<String, String> emptyMap() : ImmutableMap.copyOf(config);
this.config = (config == null) ? Collections.<String, String> emptyMap() : MutableMap.copyOf(config);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) could add asUnmodifiable or asImmutableCopy to keep the immutability.

@neykov
Copy link
Member

neykov commented Apr 5, 2016

Looks good, will wait for the build to complete and merge.

@asfgit asfgit merged commit 067c208 into apache:master Apr 6, 2016
asfgit pushed a commit that referenced this pull request Apr 6, 2016
Rest API location transformers use mutable map

LocationConfig contains null values which Guava's ImmutableMap rejects with a NullPointerException.

This fixes an error observed when deploying the "Template 1: Server" sample to localhost then running `br application <id>` with the CLI. The output from the CLI was "500 Server Error". The server logs contained:

```
java.lang.NullPointerException: null value in entry: byon.machineSpecs=null
	at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:33) ~[com.google.guava-guava-16.0.1.jar:na]
	at com.google.common.collect.ImmutableMap.entryOf(ImmutableMap.java:135) ~[com.google.guava-guava-16.0.1.jar:na]
	at com.google.common.collect.ImmutableMap$Builder.put(ImmutableMap.java:206) ~[com.google.guava-guava-16.0.1.jar:na]
	at org.apache.brooklyn.rest.transform.LocationTransformer.copyConfig(LocationTransformer.java:128) ~[org.apache.brooklyn-brooklyn-rest-resources-0.10.0-SNAPSHOT.jar:0.10.0-SNAPSHOT]
	at org.apache.brooklyn.rest.transform.LocationTransformer.newInstance(LocationTransformer.java:189) ~[org.apache.brooklyn-brooklyn-rest-resources-0.10.0-SNAPSHOT.jar:0.10.0-SNAPSHOT]
	at org.apache.brooklyn.rest.resources.LocationResource.get(LocationResource.java:139) ~[org.apache.brooklyn-brooklyn-rest-resources-0.10.0-SNAPSHOT.jar:0.10.0-SNAPSHOT]
	at org.apache.brooklyn.rest.resources.LocationResource.get(LocationResource.java:132) ~[org.apache.brooklyn-brooklyn-rest-resources-0.10.0-SNAPSHOT.jar:0.10.0-SNAPSHOT]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_05]

```
@sjcorbett sjcorbett deleted the fix/location-spec branch April 6, 2016 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants