You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2020/06/10 07:06:44 UTC

[GitHub] [druid] jihoonson opened a new pull request #10013: Add NonnullPair

jihoonson opened a new pull request #10013:
URL: https://github.com/apache/druid/pull/10013


   ### Description
   
   `Pair` is useful when you associate two things explicitly, but it allows nulls for both `lhs` and `rhs` which sometimes leads to a false warning for missing null checks. This is not only annoying but also error-prone if we change something nullable to be nonnull. This PR adds a simple class `NonnullPair` which extends `Pair` but disallows nulls. I also modified `CompactionTask` to use it as an example. `NonnullPair` extends `Pair` only because it was easy to implement and I wanted to avoid duplicate code. However, this causes the same false warning for missing null checks when you access the variables directly such as `nonnullPair.lhs`. This is inevitable since they are defined as public in `Pair`, we can avoid it by changing it to not extend `Pair`. I'm open to any suggestion.
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/licenses.yaml)
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson merged pull request #10013: Add NonnullPair

Posted by GitBox <gi...@apache.org>.
jihoonson merged pull request #10013:
URL: https://github.com/apache/druid/pull/10013


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson commented on pull request #10013: Add NonnullPair

Posted by GitBox <gi...@apache.org>.
jihoonson commented on pull request #10013:
URL: https://github.com/apache/druid/pull/10013#issuecomment-649726856


   > Though now I wonder if `Pair` should be renamed `NullablePair` and this should be renamed `Pair` 🤔 😜
   
   Yeah, I agree it would be better. However, Intellij finds 1286 usages of `Pair` as of now, doing so will cause bunch of potential conflicts.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] clintropolis commented on a change in pull request #10013: Add NonnullPair

Posted by GitBox <gi...@apache.org>.
clintropolis commented on a change in pull request #10013:
URL: https://github.com/apache/druid/pull/10013#discussion_r438345810



##########
File path: core/src/main/java/org/apache/druid/java/util/common/NonnullPair.java
##########
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.java.util.common;
+
+import com.google.common.base.Preconditions;
+
+public class NonnullPair<L, R> extends Pair<L, R>
+{
+  public NonnullPair(L lhs, R rhs)
+  {
+    super(Preconditions.checkNotNull(lhs, "lhs"), Preconditions.checkNotNull(rhs, "rhs"));
+  }
+
+  public L left()

Review comment:
       For consistency, should this have the same shape as `Pair` where `lhs` and `rhs` are just public fields?  (or should it look like this class?)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson edited a comment on pull request #10013: Add NonnullPair

Posted by GitBox <gi...@apache.org>.
jihoonson edited a comment on pull request #10013:
URL: https://github.com/apache/druid/pull/10013#issuecomment-649726856


   @clintropolis thank you for the review.
   
   > Though now I wonder if `Pair` should be renamed `NullablePair` and this should be renamed `Pair` 🤔 😜
   
   Yeah, I agree it would be better. However, Intellij finds 1286 usages of `Pair` as of now, doing so will cause bunch of potential conflicts.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson commented on a change in pull request #10013: Add NonnullPair

Posted by GitBox <gi...@apache.org>.
jihoonson commented on a change in pull request #10013:
URL: https://github.com/apache/druid/pull/10013#discussion_r444642013



##########
File path: core/src/main/java/org/apache/druid/java/util/common/NonnullPair.java
##########
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.java.util.common;
+
+import com.google.common.base.Preconditions;
+
+public class NonnullPair<L, R> extends Pair<L, R>
+{
+  public NonnullPair(L lhs, R rhs)
+  {
+    super(Preconditions.checkNotNull(lhs, "lhs"), Preconditions.checkNotNull(rhs, "rhs"));
+  }
+
+  public L left()

Review comment:
       I think it would be better to encapsulate them in `Pair` in terms of OOP (maybe aesthetically better too), but I don't really have a strong preference here since both fields in `Pair` are final. `Pair` is already in use everywhere so I changed `NonnullPair` to be consistent.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org