Skip to content

NoSuchElementException throw from lastOption #12572

@JoeCqupt

Description

@JoeCqupt

Reproduction steps

Scala version: 2.13.x

  def main(args: Array[String]): Unit = {


    val map: ConcurrentSkipListMap[Int, Int] = new ConcurrentSkipListMap[Int, Int]();
    map.put(1, 1);
    map.put(2, 3);
    map.put(3, 4);
    val subMap = map.subMap(1, 3)
    val values = subMap.values().asScala
    
    // Thead-A 
    values.lastOption.get

    // Thead-B 
    map.clear()
  }

it will occur under specific circumstances....... (Not necessarily)

Problem

when i use concurrent data structure, Iterable#lastOption maybe throw NoSuchElementException

image

According to the note of method, it did not declare will throw NoSuchElementException. i think we should avoid that

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions