You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2020/01/07 02:38:52 UTC

[GitHub] [zookeeper] belugabehr opened a new pull request #1203: ZOOKEEPER-3676: Clean Up TxnLogProposalIterator

belugabehr opened a new pull request #1203: ZOOKEEPER-3676: Clean Up TxnLogProposalIterator
URL: https://github.com/apache/zookeeper/pull/1203
 
 
   

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [zookeeper] ztzg commented on a change in pull request #1203: ZOOKEEPER-3676: Clean Up TxnLogProposalIterator

Posted by GitBox <gi...@apache.org>.
ztzg commented on a change in pull request #1203: ZOOKEEPER-3676: Clean Up TxnLogProposalIterator
URL: https://github.com/apache/zookeeper/pull/1203#discussion_r364104829
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/TxnLogProposalIterator.java
 ##########
 @@ -87,23 +87,16 @@ public void remove() {
      * transaction records
      */
     public void close() {
-        if (itr != null) {
-            try {
-                itr.close();
-            } catch (IOException ioe) {
-                LOG.warn("Error closing file iterator", ioe);
-            }
+        try {
+            itr.close();
+        } catch (IOException ioe) {
+            LOG.warn("Error closing file iterator", ioe);
         }
     }
 
-    private TxnLogProposalIterator() {
-    }
-
-    public TxnLogProposalIterator(TxnIterator itr) {
-        if (itr != null) {
-            this.itr = itr;
-            hasNext = (itr.getHeader() != null);
-        }
+    public TxnLogProposalIterator(final TxnIterator itr) {
+        this.itr = Objects.requireNonNull(itr);
+        this.hasNext = (itr.getHeader() != null);
 
 Review comment:
   @maoling: @belugabehr explains this in the description section of [ZOOKEEPER-3676](https://issues.apache.org/jira/browse/ZOOKEEPER-3676):
   
   > The the code manually returns an emptyIterator  when an error occurs, but it's also possible to return an emptyIterator by passing 'null' to the TxnLogProposalIterator constructor.  This is a bit ambiguous... why allow both?  Null values 'suck' so I think it's better to just make sure that emptyIterator is returned where needed an throw NPE if a 'null' value is passed in.
   

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [zookeeper] anmolnar commented on a change in pull request #1203: ZOOKEEPER-3676: Clean Up TxnLogProposalIterator

Posted by GitBox <gi...@apache.org>.
anmolnar commented on a change in pull request #1203: ZOOKEEPER-3676: Clean Up TxnLogProposalIterator
URL: https://github.com/apache/zookeeper/pull/1203#discussion_r373911046
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/TxnLogProposalIterator.java
 ##########
 @@ -87,23 +87,16 @@ public void remove() {
      * transaction records
      */
     public void close() {
-        if (itr != null) {
-            try {
-                itr.close();
-            } catch (IOException ioe) {
-                LOG.warn("Error closing file iterator", ioe);
-            }
+        try {
+            itr.close();
+        } catch (IOException ioe) {
+            LOG.warn("Error closing file iterator", ioe);
         }
     }
 
-    private TxnLogProposalIterator() {
-    }
-
-    public TxnLogProposalIterator(TxnIterator itr) {
-        if (itr != null) {
-            this.itr = itr;
-            hasNext = (itr.getHeader() != null);
-        }
+    public TxnLogProposalIterator(final TxnIterator itr) {
+        this.itr = Objects.requireNonNull(itr);
+        this.hasNext = (itr.getHeader() != null);
 
 Review comment:
   Makes sense to me.
   I think it would also worth to cover this behavior with unit tests.

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [zookeeper] maoling commented on a change in pull request #1203: ZOOKEEPER-3676: Clean Up TxnLogProposalIterator

Posted by GitBox <gi...@apache.org>.
maoling commented on a change in pull request #1203: ZOOKEEPER-3676: Clean Up TxnLogProposalIterator
URL: https://github.com/apache/zookeeper/pull/1203#discussion_r364076527
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/TxnLogProposalIterator.java
 ##########
 @@ -87,23 +87,16 @@ public void remove() {
      * transaction records
      */
     public void close() {
-        if (itr != null) {
-            try {
-                itr.close();
-            } catch (IOException ioe) {
-                LOG.warn("Error closing file iterator", ioe);
-            }
+        try {
+            itr.close();
+        } catch (IOException ioe) {
+            LOG.warn("Error closing file iterator", ioe);
         }
     }
 
-    private TxnLogProposalIterator() {
-    }
-
-    public TxnLogProposalIterator(TxnIterator itr) {
-        if (itr != null) {
-            this.itr = itr;
-            hasNext = (itr.getHeader() != null);
-        }
+    public TxnLogProposalIterator(final TxnIterator itr) {
+        this.itr = Objects.requireNonNull(itr);
+        this.hasNext = (itr.getHeader() != null);
 
 Review comment:
   - AFAIK, `Objects.requireNonNull` will throw an `NPE` when `itr` is null, is the new code changes the logic? Actually, `itr` can be null

----------------------------------------------------------------
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


With regards,
Apache Git Services