Skip to content

Commit

Permalink
fix CCE for RoaringTagIndex.empty (#1312)
Browse files Browse the repository at this point in the history
Fix ClassCastException for casting the array based on
the generic type.
  • Loading branch information
brharrington authored Jun 2, 2021
1 parent cebb24f commit 0bfcc5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import com.netflix.atlas.core.model.ItemId
import com.netflix.atlas.core.model.Query
import com.netflix.atlas.core.model.Tag
import com.netflix.atlas.core.model.TaggedItem
import com.netflix.atlas.core.util.ArrayHelper
import com.netflix.atlas.core.util.IntIntHashMap
import com.netflix.atlas.core.util.IntRefHashMap
import com.netflix.atlas.core.util.LongHashSet
import com.netflix.atlas.core.util.RefIntHashMap
import org.roaringbitmap.RoaringBitmap
import org.slf4j.LoggerFactory

import scala.reflect.ClassTag

/**
* Create a new index based on roaring bitmaps.
*
Expand Down Expand Up @@ -493,8 +494,8 @@ class RoaringTagIndex[T <: TaggedItem](items: Array[T], stats: IndexStats) exten
object RoaringTagIndex {
private val logger = LoggerFactory.getLogger(getClass)

def empty[T <: TaggedItem]: RoaringTagIndex[T] = {
new RoaringTagIndex(ArrayHelper.newInstance[T](0), new IndexStats())
def empty[T <: TaggedItem: ClassTag]: RoaringTagIndex[T] = {
new RoaringTagIndex(new Array[T](0), new IndexStats())
}

private[index] def hasNonEmptyIntersection(b1: RoaringBitmap, b2: RoaringBitmap): Boolean = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.netflix.atlas.core.index

import com.netflix.atlas.core.model.Datapoint
import com.netflix.atlas.core.model.TimeSeries
import org.roaringbitmap.RoaringBitmap

Expand All @@ -24,6 +25,11 @@ class RoaringTagIndexSuite extends TagIndexSuite {
new RoaringTagIndex(TagIndexSuite.dataset.toArray, new IndexStats())
}

test("empty") {
val idx = RoaringTagIndex.empty[Datapoint]
assert(idx.size == 0)
}

test("hasNonEmptyIntersection: empty, empty") {
val b1 = new RoaringBitmap()
val b2 = new RoaringBitmap()
Expand Down

0 comments on commit 0bfcc5a

Please sign in to comment.