Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL crash when toString returns null #17333

Closed
bishabosha opened this issue Apr 24, 2023 · 2 comments · Fixed by #17336
Closed

REPL crash when toString returns null #17333

bishabosha opened this issue Apr 24, 2023 · 2 comments · Fixed by #17336

Comments

@bishabosha
Copy link
Member

bishabosha commented Apr 24, 2023

Compiler version

3.2.2

Minimized code

scala> class Foo { override def toString = null }
// defined class Foo
                                                                                                                 
scala> new Foo()

Output (click arrow to expand)

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "str" is null
	at dotty.tools.repl.Rendering.truncate(Rendering.scala:92)
	at dotty.tools.repl.Rendering.classLoader$$anonfun$1(Rendering.scala:79)
	at dotty.tools.repl.Rendering.classLoader$$anonfun$adapted$1(Rendering.scala:85)
	at dotty.tools.repl.Rendering.replStringOf(Rendering.scala:102)
	at dotty.tools.repl.Rendering.$anonfun$5(Rendering.scala:115)
	at scala.Option.map(Option.scala:242)
	at dotty.tools.repl.Rendering.valueOf(Rendering.scala:115)
	at dotty.tools.repl.Rendering.renderVal(Rendering.scala:157)
	at dotty.tools.repl.ReplDriver.$anonfun$7(ReplDriver.scala:365)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.repl.ReplDriver.extractAndFormatMembers$1(ReplDriver.scala:371)
	at dotty.tools.repl.ReplDriver.renderDefinitions$$anonfun$2(ReplDriver.scala:403)
	at scala.Option.map(Option.scala:242)
	at dotty.tools.repl.ReplDriver.renderDefinitions(ReplDriver.scala:409)
	at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:307)
	at scala.util.Either.fold(Either.scala:189)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:323)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:248)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:168)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:171)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:191)
	at dotty.tools.repl.ReplDriver.runBody$$anonfun$1(ReplDriver.scala:179)
	at dotty.tools.runner.ScalaClassLoader$.asContext(ScalaClassLoader.scala:80)
	at dotty.tools.repl.ReplDriver.runBody(ReplDriver.scala:179)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:171)
	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:133)
	at dotty.tools.repl.Main$.main(Main.scala:7)
	at dotty.tools.repl.Main.main(Main.scala)

Expectation

Scala 2.13 prints the following:

scala> class Foo { override def toString = null }
class Foo

scala> new Foo()
val res0: Foo = null toString
@bishabosha bishabosha added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 24, 2023
@som-snytt
Copy link
Contributor

Handled correctly in 3.2.1, but not by truncation check.

@som-snytt
Copy link
Contributor

I submitted a quick PR as a refresher in using Scala 3 syntax to write Scala 3 tests.

@KacperFKorban KacperFKorban added area:repl and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 25, 2023
bishabosha added a commit that referenced this issue Mar 1, 2024
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
@Kordyjan Kordyjan modified the milestones: 3.4.2, 3.5.0 May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants