public GatewaySenderEventImpl makeHeapCopyIfOffHeap() {
    if (value != null || substituteValue != null) {
      // we have the value stored on the heap so return this
      return this;
    } else {
      Object v = valueObj;
      if (v == null) {
        if (valueObjReleased) {
          // this means that the original off heap value was freed
          return null;
        } else {
          return this;
        }
      }
      if (v instanceof StoredObject && ((StoredObject) v).hasRefCount()) {
        try {
          return makeCopy();
        } catch (IllegalStateException ex) {
          // this means that the original off heap value was freed
          return null;
        }
      } else {
        // the valueObj does not use refCounts so just return this.
        return this;
      }
    }
  }
Make a heap copy of this off-heap event and return it. A copy only needs to be made if the
event's value is stored off-heap. If it is already on the java heap then just return "this". If
it was stored off-heap and is no longer available (because it was released) then return null.
geode-core/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventImpl.java