This is an automated email from the ASF dual-hosted git repository.

ayegorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b15963748 Replace assert statements with explicit checks (#4390)
9b15963748 is described below

commit 9b15963748966ab32a13e7fde0bff2fc6d4f386f
Author: ZhangJian He <[email protected]>
AuthorDate: Fri May 31 06:22:26 2024 +0800

    Replace assert statements with explicit checks (#4390)
    
    Signed-off-by: ZhangJian He <[email protected]>
---
 .../src/main/java/org/apache/distributedlog/BKLogSegmentWriter.java | 6 +++++-
 .../java/org/apache/distributedlog/impl/metadata/BKDLConfig.java    | 4 +++-
 .../main/java/org/apache/distributedlog/zk/ZKVersionedSetOp.java    | 4 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git 
a/stream/distributedlog/core/src/main/java/org/apache/distributedlog/BKLogSegmentWriter.java
 
b/stream/distributedlog/core/src/main/java/org/apache/distributedlog/BKLogSegmentWriter.java
index fdf34e275d..7ac75b9927 100644
--- 
a/stream/distributedlog/core/src/main/java/org/apache/distributedlog/BKLogSegmentWriter.java
+++ 
b/stream/distributedlog/core/src/main/java/org/apache/distributedlog/BKLogSegmentWriter.java
@@ -1192,7 +1192,11 @@ class BKLogSegmentWriter implements LogSegmentWriter, 
AddCallback, Runnable, Siz
         }
         lastEntryId = entryId;
 
-        assert (ctx instanceof BKTransmitPacket);
+        if (!(ctx instanceof BKTransmitPacket)) {
+            LOG.error("Log segment {} received addComplete with invalid 
context {}",
+                    fullyQualifiedLogSegment, ctx);
+            return;
+        }
         final BKTransmitPacket transmitPacket = (BKTransmitPacket) ctx;
 
         // Time from transmit until receipt of addComplete callback
diff --git 
a/stream/distributedlog/core/src/main/java/org/apache/distributedlog/impl/metadata/BKDLConfig.java
 
b/stream/distributedlog/core/src/main/java/org/apache/distributedlog/impl/metadata/BKDLConfig.java
index ef2277eb52..b32b3193a0 100644
--- 
a/stream/distributedlog/core/src/main/java/org/apache/distributedlog/impl/metadata/BKDLConfig.java
+++ 
b/stream/distributedlog/core/src/main/java/org/apache/distributedlog/impl/metadata/BKDLConfig.java
@@ -73,7 +73,9 @@ public class BKDLConfig implements DLConfig {
                 dlConfig = oldDLConfig;
             }
         }
-        assert (dlConfig instanceof BKDLConfig);
+        if (!(dlConfig instanceof BKDLConfig)) {
+            throw new IllegalStateException("Invalid DLConfig type : " + 
dlConfig.getClass().getName());
+        }
         return (BKDLConfig) dlConfig;
     }
 
diff --git 
a/stream/distributedlog/core/src/main/java/org/apache/distributedlog/zk/ZKVersionedSetOp.java
 
b/stream/distributedlog/core/src/main/java/org/apache/distributedlog/zk/ZKVersionedSetOp.java
index ac33119a2c..9f7b03db0e 100644
--- 
a/stream/distributedlog/core/src/main/java/org/apache/distributedlog/zk/ZKVersionedSetOp.java
+++ 
b/stream/distributedlog/core/src/main/java/org/apache/distributedlog/zk/ZKVersionedSetOp.java
@@ -55,7 +55,9 @@ public class ZKVersionedSetOp extends ZKOp {
         if (null == opResult) {
             cause = t;
         } else {
-            assert (opResult instanceof OpResult.ErrorResult);
+            if (!(opResult instanceof OpResult.ErrorResult)) {
+                throw new IllegalStateException("Invalid op result : " + 
opResult);
+            }
             OpResult.ErrorResult errorResult = (OpResult.ErrorResult) opResult;
             if (KeeperException.Code.OK.intValue() == errorResult.getErr()) {
                 cause = t;

Reply via email to