X Tutup
Skip to content

Refactor primitive type fields to be of object type in JSON objects#313

Merged
marcuslinke merged 12 commits intomasterfrom
issue-246
Nov 5, 2015
Merged

Refactor primitive type fields to be of object type in JSON objects#313
marcuslinke merged 12 commits intomasterfrom
issue-246

Conversation

@marcuslinke
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do you need it?

@KostyaSha
Copy link
Copy Markdown
Member

@marcuslinke my thoughts:

  • is* should be used only for boolean primitives, get* or has* for Objects
  • primitive -> Object doesn't make sense for stream handling/callback internals (was all this change done with sed?)
  • all Nullable return values and fields should be annotated with @CheckForNull
  • withSomething() looks redundant in interface and it not so difficult to set explicit values for library consumers
  • many places will have null checks for data values if (getSomething() != null && getSomething() { so maybe it makes sense to keep isSomething() methods that will have this null check internally (see BuildImageCmd where i kept backward compatibility for primitive method and used Object for data field

@marcuslinke
Copy link
Copy Markdown
Contributor Author

@KostyaSha Thanks for the review! Yes, I initially did search and replace for booleans, so I need to review all of these replacements. I like your suggestions especially that it will retain backward compatibility. However, it will take some time as I'm quite busy with other things at the moment.

@KostyaSha
Copy link
Copy Markdown
Member

@marcuslinke my suggestion will be to start doing it partially. I can start with critical for docker-plugin API commands and PR changes. @marcuslinke btw, backward compatibility will be broken in any release because all methods defined in interface that requires extending fields/methods for every docker API update. So it seems that we should forget about compatibilities in X.Y.

Marcus Linke added 2 commits September 17, 2015 22:22
Conflicts:
	src/main/java/com/github/dockerjava/api/command/LogContainerCmd.java
	src/main/java/com/github/dockerjava/api/model/BuildResponseItem.java
	src/main/java/com/github/dockerjava/api/model/PullResponseItem.java
	src/main/java/com/github/dockerjava/api/model/PushResponseItem.java
	src/main/java/com/github/dockerjava/api/model/ResponseItem.java
	src/main/java/com/github/dockerjava/core/command/LogContainerCmdImpl.java
	src/main/java/com/github/dockerjava/jaxrs/LogContainerCmdExec.java
@marcuslinke
Copy link
Copy Markdown
Contributor Author

@KostyaSha After thinking about it again I want to discuss these additional get/has/is methods that return primitives (in commands):

  • Examining existing command objects isn't the general use case I guess, so handling null cases might be acceptable for the caller
  • Returning primitives introduces some kind of default value which might be OK for boolean but what about long/int values (see tail member in log command for example)?

@KostyaSha
Copy link
Copy Markdown
Member

Maybe attach to request only non-null values without checking what is default plus annotate everything with @CheckForNull? If docker has some default values, then it's probably not a docker-java issue to show user what is default.

@marcuslinke
Copy link
Copy Markdown
Contributor Author

OK, so lets summarize:

  • dropping get/is/has methods that return primitives like boolean, long, int
  • by annotating json objects with @JsonInclude(Include.NON_NULL) we can consider that only non-null values are sent with the request
  • by annotating appropriate get/has/is methods with @CheckForNull FindBugs can find missing null checks in client code

Do you agree?

@KostyaSha
Copy link
Copy Markdown
Member

Sounds good

@KostyaSha
Copy link
Copy Markdown
Member

My idea about removing withSomething() was to minimise code in library.

@marcuslinke
Copy link
Copy Markdown
Contributor Author

Yeah. I will probably remove this also. By the way, according to http://ehc.ac/p/findbugs/bugs/334/ @CheckForNull can be annotated at the interface level. So I will remove this annotation from the implementation ('BuildImageCmdImpl'), OK?

@KostyaSha
Copy link
Copy Markdown
Member

Right, for method return values inheritance should work.

@KostyaSha
Copy link
Copy Markdown
Member

@marcuslinke and if we do refactoring, is it possible to use Lists instead arrays?

@marcuslinke
Copy link
Copy Markdown
Contributor Author

@KostyaSha I think we could add additional methods that takes Lists.

@KostyaSha
Copy link
Copy Markdown
Member

Disclaimer: i'm not an expert of api libraries :)
@marcuslinke my main concern about List was to have easier data manipulation. For example in docker i fill create command on 2 levels. First is configuration and then launcher modifies parameters. With array if very inconvenient to do changes, it enforces casting to List, working with it and back setting to array.
So logical idea was to simplify api and place List directly.

@KostyaSha
Copy link
Copy Markdown
Member

According to google this code should work

@JsonProperty("Cmd")
private List<String> cmd;

Then you can simply use some http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.1/org/apache/commons/collections/CollectionUtils.html#isNotEmpty(java.util.Collection) or guava...

@marcuslinke
Copy link
Copy Markdown
Contributor Author

I think the main difference between arrays and lists is the aspect of mutablitity. Whereas arrays are immutable, lists in contast are not and allow the manipulation from the outside. In general I dont think this is a good idea as it may result in unexpected behaviour. So switching to lists would enforce to ensure the immutablitity by copying to (when implementing the setter) and copying from (when implementing the getter) the internal list. I would avoid this implementation effort...

@KostyaSha
Copy link
Copy Markdown
Member

Where do you see mutability issue? You can either replace List either manipulate with existed. During exec it will be send to remote.

Marcus Linke added 4 commits October 20, 2015 22:58
Conflicts:
	src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java
	src/main/java/com/github/dockerjava/api/model/HostConfig.java
	src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java
marcuslinke added a commit that referenced this pull request Nov 5, 2015
Refactor primitive type fields to be of object type in JSON objects
@marcuslinke marcuslinke merged commit 1446774 into master Nov 5, 2015
@marcuslinke marcuslinke deleted the issue-246 branch November 6, 2015 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup