Skip to content

Commit

Permalink
MONDRIAN: A better fix for the NPE issues with RolapUtil.sqlNullValue…
Browse files Browse the repository at this point in the history
… in collections. We don't do type checks unless we detect a problem with the class casting, thus maintaining the performance of the original code. A better fix would be to include metadata in the header and "flag" the presence of null, which we would include later on back into the collection. I've tried to refactor and do this, but ran into a whole bunch of other issues. For now, this fix seems reasonable, but in the long term we need to address this.

[git-p4: depot-paths = "//open/mondrian/": change = 14966]
  • Loading branch information
lucboudreau committed Feb 20, 2012
1 parent efa416e commit acdfab7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
26 changes: 26 additions & 0 deletions src/main/mondrian/rolap/RolapUtil.java
Expand Up @@ -28,6 +28,7 @@
import java.lang.reflect.*;
import java.sql.SQLException;
import java.util.*;

import javax.sql.DataSource;

/**
Expand Down Expand Up @@ -143,6 +144,31 @@ public int compareTo(Object o) {
}
}

/**
* A comparator singleton instance which can handle the presence of
* {@link RolapUtilComparable} instances in a collection.
*/
public static final Comparator ROLAP_COMPARATOR =
new RolapUtilComparator();

private static final class RolapUtilComparator<T extends Comparable<T>>
implements Comparator<T>
{
public int compare(T o1, T o2) {
try {
return o1.compareTo(o2);
} catch (ClassCastException cce) {
if (o1 instanceof RolapUtilComparable) {
return -1;
}
if (o2 instanceof RolapUtilComparable) {
return 1;
}
throw new MondrianException(cce);
}
}
}

/**
* Runtime NullMemberRepresentation property change not taken into
* consideration
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/rolap/cache/SegmentCacheIndexImpl.java
Expand Up @@ -704,7 +704,7 @@ private void findRollupCandidatesAmong(
for (SegmentColumn column : columnList) {
// For each value, which equivalence class it belongs to.
final SortedMap<Comparable, BitSet> valueMap =
new TreeMap<Comparable, BitSet>();
new TreeMap<Comparable, BitSet>(RolapUtil.ROLAP_COMPARATOR);

int h = -1;
for (SegmentHeader header : Pair.leftIter(matchingHeaders)) {
Expand Down
13 changes: 2 additions & 11 deletions src/main/mondrian/util/UtilCompatibleJdk14.java
Expand Up @@ -11,6 +11,7 @@

import mondrian.olap.Util;
import mondrian.resource.MondrianResource;
import mondrian.rolap.RolapUtil;
import mondrian.rolap.RolapUtil.RolapUtilComparable;

import org.apache.log4j.Logger;
Expand Down Expand Up @@ -174,17 +175,7 @@ public <T extends Comparable<T>> int binarySearch(
{
return Collections.binarySearch(
Arrays.asList(ts).subList(start, end), t,
new Comparator<T>() {
public int compare(T o1, T o2) {
if (o1 instanceof RolapUtilComparable) {
return -1;
}
if (o2 instanceof RolapUtilComparable) {
return 1;
}
return o1.compareTo(o2);
};
});
RolapUtil.ROLAP_COMPARATOR);
}
}

Expand Down
13 changes: 2 additions & 11 deletions src/main/mondrian/util/UtilCompatibleJdk15.java
Expand Up @@ -11,6 +11,7 @@

import mondrian.olap.Util;
import mondrian.resource.MondrianResource;
import mondrian.rolap.RolapUtil;
import mondrian.rolap.RolapUtil.RolapUtilComparable;

import org.apache.log4j.Logger;
Expand Down Expand Up @@ -180,17 +181,7 @@ public <T extends Comparable<T>> int binarySearch(
{
final int i = Collections.binarySearch(
Arrays.asList(ts).subList(start, end), t,
new Comparator<T>() {
public int compare(T o1, T o2) {
if (o1 instanceof RolapUtilComparable) {
return -1;
}
if (o2 instanceof RolapUtilComparable) {
return 1;
}
return o1.compareTo(o2);
};
});
RolapUtil.ROLAP_COMPARATOR);
return (i < 0) ? (i - start) : (i + start);
}
}
Expand Down
13 changes: 2 additions & 11 deletions src/main/mondrian/util/UtilCompatibleJdk16.java
Expand Up @@ -11,6 +11,7 @@

import mondrian.olap.Util;
import mondrian.resource.MondrianResource;
import mondrian.rolap.RolapUtil;
import mondrian.rolap.RolapUtil.RolapUtilComparable;

import org.apache.log4j.Logger;
Expand Down Expand Up @@ -97,17 +98,7 @@ public <T extends Comparable<T>> int binarySearch(
{
return Arrays.binarySearch(
ts, start, end, t,
new Comparator<T>() {
public int compare(T o1, T o2) {
if (o1 instanceof RolapUtilComparable) {
return -1;
}
if (o2 instanceof RolapUtilComparable) {
return 1;
}
return o1.compareTo(o2);
};
});
RolapUtil.ROLAP_COMPARATOR);
}
}

Expand Down

0 comments on commit acdfab7

Please sign in to comment.