mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
23.12.2015 5ff5b99fb9c9998d027b0369d6de416a8e148aeb
Ensured IndexQuery.evaluate() never returns null + updated javadoc to mention it.
Client code assumes that the returned value will never be null anyway.


IndexQuery.java:
In evaluate(), modified the javadoc to mention returned value can never be null.
In IntersectionIndexQuery and UnionIndexQuery evaluate methods, got rid of null checks.

Index.java:
In readRange(), modified the javadoc to mention returned value can never be null.
In read(), added javadoc.
In containsID() and read(), slightly modified the code to make it more compact and more readable.
2 files modified
59 ■■■■■ changed files
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Index.java 35 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/IndexQuery.java 24 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Index.java
@@ -409,39 +409,32 @@
    if (value != null)
    {
      EntryIDSet entryIDSet = newSetFromBytes(key, value);
      if (!entryIDSet.isDefined())
      if (entryIDSet.isDefined())
      {
        return ConditionResult.UNDEFINED;
        return ConditionResult.valueOf(entryIDSet.contains(entryID));
      }
      return ConditionResult.valueOf(entryIDSet.contains(entryID));
    }
    else if (trusted)
    {
      return ConditionResult.FALSE;
    }
    else
    {
      return ConditionResult.UNDEFINED;
    }
    return trusted ? ConditionResult.FALSE : ConditionResult.UNDEFINED;
  }
  /**
   * Reads the value associated to a key.
   *
   * @param txn The transaction to use for the operation
   * @param key The key to read
   * @return The non null set of entry IDs.
   */
  EntryIDSet read(ReadableStorage txn, ByteSequence key)
  {
    try
    {
      ByteString value = txn.read(getName(), key);
      if (value == null)
      if (value != null)
      {
        if(trusted)
        {
          return newDefinedSet();
        }
        else
        {
          return newUndefinedSet();
        }
        return newSetFromBytes(key, value);
      }
      return newSetFromBytes(key, value);
      return trusted ? newDefinedSet() : newUndefinedSet();
    }
    catch (StorageRuntimeException e)
    {
@@ -471,7 +464,7 @@
   *                      strictly less than the upper bound are included.
   *                      This value is ignored if the upper bound is not
   *                      specified.
   * @return The set of entry IDs.
   * @return The non null set of entry IDs.
   */
  EntryIDSet readRange(ReadableStorage txn,
      ByteSequence lower, ByteSequence upper, boolean lowerIncluded, boolean upperIncluded)
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/IndexQuery.java
@@ -52,7 +52,7 @@
   * @param debugMessage If not null, diagnostic message will be written
   *                      which will help to determine why the returned
   *                      EntryIDSet is not defined.
   * @return The EntryIDSet as a result of evaluation of this query.
   * @return The non null EntryIDSet as a result of evaluating this query
   */
  public abstract EntryIDSet evaluate(LocalizableMessageBuilder debugMessage);
@@ -136,17 +136,10 @@
    @Override
    public EntryIDSet evaluate(LocalizableMessageBuilder debugMessage)
    {
      EntryIDSet entryIDs = null;
      final EntryIDSet entryIDs = newUndefinedSet();
      for (IndexQuery query : subIndexQueries)
      {
        if (entryIDs == null)
        {
          entryIDs = query.evaluate(debugMessage);
        }
        else
        {
          entryIDs.retainAll(query.evaluate(debugMessage));
        }
        entryIDs.retainAll(query.evaluate(debugMessage));
        if (isBelowFilterThreshold(entryIDs))
        {
          break;
@@ -182,17 +175,10 @@
    @Override
    public EntryIDSet evaluate(LocalizableMessageBuilder debugMessage)
    {
      EntryIDSet entryIDs = null;
      final EntryIDSet entryIDs = newDefinedSet();
      for (IndexQuery query : subIndexQueries)
      {
        if (entryIDs == null)
        {
          entryIDs = query.evaluate(debugMessage);
        }
        else
        {
          entryIDs.addAll(query.evaluate(debugMessage));
        }
        entryIDs.addAll(query.evaluate(debugMessage));
        if (entryIDs.isDefined() && entryIDs.size() >= CURSOR_ENTRY_LIMIT)
        {
          break;