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/08 08:11:19 UTC

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

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