Skip to content

Java standard collections bypass safe mode #25759

@Linyxus

Description

@Linyxus

Compiler version

main

Minimized code

import language.experimental.safe
def assertPure(op: () -> Unit): Unit = ()
def testQueue(): Unit =
  val q = new java.util.concurrent.ConcurrentLinkedQueue[String]()
  assertPure: () =>
    q.add("secret")  // should be error, but ok

def testArrayList(): Unit =
  val xs = new java.util.ArrayList[String]()
  assertPure: () =>
    xs.add("secret")  // should be error, but ok

def testHashMap(): Unit =
  val m = new java.util.HashMap[String, String]()
  assertPure: () =>
    m.put("leak", "secret")  // should be error, but ok

def testArrayDeque(): Unit =
  val dq = new java.util.ArrayDeque[String]()
  assertPure: () =>
    dq.addLast("secret")  // should be error, but ok

Output

It compiles.

Expectation

Should be tons of errors.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions