This is an automated email from the ASF dual-hosted git repository.
jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new d882065 GEODE-3: do not use Assert in production code. use explicit
exception. (#2471)
d882065 is described below
commit d8820654ee66cf6796f9ff40b934983db293ba40
Author: jinmeiliao <[email protected]>
AuthorDate: Fri Sep 14 11:00:59 2018 -0700
GEODE-3: do not use Assert in production code. use explicit exception.
(#2471)
* turning on assertion in classloader would not play nicely in jdk9 and
later.
---
.../internal/offheap/OffHeapRegionEntryHelper.java | 12 +++++++++---
.../offheap/OffHeapRegionEntryHelperJUnitTest.java | 21 ---------------------
2 files changed, 9 insertions(+), 24 deletions(-)
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/offheap/OffHeapRegionEntryHelper.java
b/geode-core/src/main/java/org/apache/geode/internal/offheap/OffHeapRegionEntryHelper.java
index 68e0391..7b03487 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/offheap/OffHeapRegionEntryHelper.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/offheap/OffHeapRegionEntryHelper.java
@@ -276,7 +276,9 @@ public class OffHeapRegionEntryHelper {
}
static int decodeAddressToDataSize(long addr) {
- assert (addr & ENCODED_BIT) != 0;
+ if ((addr & ENCODED_BIT) == 0) {
+ throw new AssertionError("Invalid address: " + addr);
+ }
boolean isLong = (addr & LONG_BIT) != 0;
if (isLong) {
return 9;
@@ -291,7 +293,9 @@ public class OffHeapRegionEntryHelper {
* @throws UnsupportedOperationException if the address has compressed data
*/
static byte[] decodeUncompressedAddressToBytes(long addr) {
- assert (addr & COMPRESSED_BIT) == 0 : "Did not expect encoded address to
be compressed";
+ if ((addr & COMPRESSED_BIT) != 0) {
+ throw new AssertionError("Did not expect encoded address to be
compressed");
+ }
return decodeAddressToRawBytes(addr);
}
@@ -300,7 +304,9 @@ public class OffHeapRegionEntryHelper {
* compressed then the raw bytes are the compressed bytes.
*/
static byte[] decodeAddressToRawBytes(long addr) {
- assert (addr & ENCODED_BIT) != 0;
+ if ((addr & ENCODED_BIT) == 0) {
+ throw new AssertionError("Invalid address: " + addr);
+ }
int size = (int) ((addr & SIZE_MASK) >> SIZE_SHIFT);
boolean isLong = (addr & LONG_BIT) != 0;
byte[] bytes;
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/offheap/OffHeapRegionEntryHelperJUnitTest.java
b/geode-core/src/test/java/org/apache/geode/internal/offheap/OffHeapRegionEntryHelperJUnitTest.java
index 618ac47..b210e82 100644
---
a/geode-core/src/test/java/org/apache/geode/internal/offheap/OffHeapRegionEntryHelperJUnitTest.java
+++
b/geode-core/src/test/java/org/apache/geode/internal/offheap/OffHeapRegionEntryHelperJUnitTest.java
@@ -25,9 +25,7 @@ import static org.mockito.Mockito.when;
import java.nio.ByteBuffer;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
@@ -55,25 +53,6 @@ public class OffHeapRegionEntryHelperJUnitTest {
private static final Long VALUE_IS_NOT_ENCODABLE = 0L;
- private static Boolean assertionsEnabled;
-
- @BeforeClass
- public static void setUpOnce() {
- try {
- assert false;
- assertionsEnabled = false;
- } catch (AssertionError e) {
- assertionsEnabled = true;
- }
- ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
- System.out.println("assertionsEnabled = " + assertionsEnabled);
- }
-
- @AfterClass
- public static void tearDownOnce() {
-
ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(assertionsEnabled);
- }
-
private MemoryAllocator ma;
@Before