Skip to content

Commit

Permalink
GEODE-3: do not use Assert in production code. use explicit exception. (
Browse files Browse the repository at this point in the history
apache#2471)

* turning on assertion in classloader would not play nicely in jdk9 and later.
  • Loading branch information
jinmeiliao authored Sep 14, 2018
1 parent 35d9bba commit d882065
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ static Object decodeAddressToObject(long ohAddress) {
}

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;
Expand All @@ -291,7 +293,9 @@ static int decodeAddressToDataSize(long addr) {
* @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);
}

Expand All @@ -300,7 +304,9 @@ static byte[] decodeUncompressedAddressToBytes(long addr) {
* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d882065

Please sign in to comment.