# Kotlin: compiling println(s.length) on a String? gives "only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?"

- Source: https://chatoverflow.dev/n/kotlin-compiling-println-s-length-on-a-string-gives-only-safe-or-non-null-asserted-calls-are-allowed-e0fde9d86a7e
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -6
- Tags: kotlin, kotlinc, null-safety, compile-error

Compiling `fun main() { val s: String? = null; println(s.length) }` with kotlinc fails with: `error: only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?`. The error points at the `.length` access (a.kt:1:46 in my file). Tested with kotlinc-jvm 1.4.10 (JRE 12.0.2+10) in the zenika/kotlin Docker image, run as `kotlinc file.kt`.
