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

provide initialization of oldValue array property in SetAttributesCommand #230

Merged
merged 2 commits into from May 16, 2018

Conversation

nprigour
Copy link
Contributor

@nprigour nprigour commented May 25, 2017

oldValue array is not initialized during command construction time resulting in a NPE when trying to set values to an array element during run() or rollback method

Signed-off-by: Nikolaos Pringouris nprigour@gmail.com

SetAttributesCommand constructor

Signed-off-by: Nikolaos Pringouris <nprigour@gmail.com>
@@ -60,6 +60,7 @@ public SetAttributesCommand( IBlockingProvider<SimpleFeature> feature, IBlocking
Object value[] ) {
this.xpath = xpath;
this.value = value;
this.oldValue = new Object[value.length];
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe its worth to check for null of value here. Looks like the only caller is EditFeature where value is set. However this is an implementation detail but from javadoc constructor argument description it could be possible if somebody like to implement to "clean"/"empty" attributes.

I would suggest to check for null in both constructors or even delegate from the second to the first one using:

public SetAttributesCommand( String xpath[], Object value[] ) {
        this(new EditFeatureProvider(this), new EditLayerProvider(this), xpath, value); 
}

Copy link
Contributor Author

@nprigour nprigour Sep 13, 2017

Choose a reason for hiding this comment

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

Hi @fgdrf,

  • Delegation the way you specify it is not possible since we cannot refer to 'this' while explicitly invoking a constructor.
  • Regarding null value check what can be done is to put an Assert.isNotNull for both xpath[] and value[] at the beginning of each constructor, since providing null values for these parameters is more or less meaningless for this specific command and should be not permitted (the subsequent execution of the run method will fail). Generally if a user wants to clean/empty attributes he should set a value[] array with the proper length and null values for each array element desired to be cleaned

If this will this suffice your request I will add the Assertion checks asap.

Copy link
Contributor

Choose a reason for hiding this comment

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

Delegation the way you specify it is not possible since we cannot refer to 'this' while explicitly invoking a constructor.

Oh yes, haven't seen this. However, the first Constructor is never used in codebase. I'll provide a pull request to eliminate it.

I'm wondering a bit why value.length is used while the loop

		// for loop to get the old values
		for(int i = 0; i < xpath.length; i++){
		    oldValue[i] = feature2.getAttribute(xpath[i]);
		}

uses xpath.lenght. I assume that object-Array might have same length but who knows ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

see pull nprigour#10 for validation. I would merge afterwards..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok with the validations. My only objection is about removing of the unused constructor. In my opinion, although not used at the moment it might be worth to keep it assuming a more complete SDK. After all SetAttributesCommand class is a generalization of SetAttributeCommand allowing for multiple attribute sets. There a similar constructor does exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

Going to change the pull ;)

@fgdrf fgdrf added the bug label May 16, 2018
@fgdrf fgdrf added this to the 2.1.0 milestone May 16, 2018
Signed-off-by: Frank Gasdorf <fgdrf@users.sourceforge.net>
@nprigour
Copy link
Contributor Author

I just rebased and merged your pull request

@fgdrf fgdrf merged commit 8cf8ba1 into locationtech:master May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants