question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception throw when compiling a project: java.lang.NullPointerException: tried to cast away nullability, but value is null

See original GitHub issue

Compiler version

3.1.3

Minimized example

I am afraid I do not have a minimized example yet, I will need some advice on how to extract it.

I am trying to port my complex project to Scala 3. I have fixed most deprecation warnings in 2.13 and upgraded almost all libraries. I am not getting much compiler errors any more, but still use both “-source:3.0-migration” and “-Xignore-scala2-macros”, as not all libraries are ported and I still need to compile the project as 2.13 one.

Output

When building my project with Scala 3.1.3, I get following error:

Exception when compiling 382 sources to … java.lang.NullPointerException: tried to cast away nullability, but value is null

I am not told which part of the project / what particulat Scala source is the compiler working at, therefore I have no idea how could I pinpoint the problem.

The top of the callstack is:

[error] java.lang.NullPointerException: tried to cast away nullability, but value is null
[error] scala.runtime.Scala3RunTime$.nn(Scala3RunTime.scala:19)
[error] dotty.tools.dotc.core.OrderingConstraint.swapKey$1(OrderingConstraint.scala:495)
[error] dotty.tools.dotc.core.OrderingConstraint.subst(OrderingConstraint.scala:496)
[error] dotty.tools.dotc.core.OrderingConstraint.subst(OrderingConstraint.scala:494)
[error] dotty.tools.dotc.core.TyperState.ensureNotConflicting$$anonfun$1(TyperState.scala:181)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.core.TyperState.ensureNotConflicting(TyperState.scala:182)
[error] dotty.tools.dotc.core.TyperState.mergeConstraintWith(TyperState.scala:193)
[error] dotty.tools.dotc.core.TyperState.commit(TyperState.scala:163)
[error] dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3111)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1002)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1040)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:327)
[error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:117)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2832)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2895)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3080)
[error] dotty.tools.dotc.typer.Typer.$anonfun$47(Typer.scala:2278)
[error] dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:248)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2278)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2808)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2894)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2986)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3036)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2476)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2820)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2824)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2894)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2986)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3036)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2476)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2820)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2824)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2894)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2986)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3036)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2603)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2865)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2895)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3013)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3036)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2603)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2865)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2895)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3080)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:43)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:50)
[error] scala.Function0.apply$mcV$sp(Function0.scala:39)
[error] dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:414)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:50)
[error] dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:84)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:84)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:225)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1328)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:236)```

Expectation

I think compiler can show errors, but should never throw exceptions.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
oderskycommented, Aug 22, 2022

I could reproduce it now. The two files have to be compiled as State.scala and Config.scala, in that order on the command line. If the order is swapped, it compiles.

I.e.

~/workspace/dotty/tests/pos/i15845> sc state/Config.scala State.scala
~/workspace/dotty/tests/pos/i15845> sc State.scala state/Config.scala
exception occurred while typechecking State.scala
exception occurred while compiling State.scala, state/Config.scala
java.lang.NullPointerException: tried to cast away nullability, but value is null while compiling State.scala, state/Config.scala
Exception in thread "main" java.lang.NullPointerException: tried to cast away nullability, but value is null
	at scala.runtime.Scala3RunTime$.nnFail(Scala3RunTime.scala:28)
	at dotty.tools.dotc.core.OrderingConstraint.swapKey$1(OrderingConstraint.scala:501)
0reactions
OndrejSpanelcommented, Aug 22, 2022

It it not Windows specific, it can be reproduced on a GitHub runner using Ubuntu, see https://github.com/OndrejSpanel/scala3-error-repro/runs/7954324298?check_suite_focus=true

I think the GitHub runner environment should be clean and there should be no class-path issues on it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IllegalArgumentException or NullPointerException for a null ...
This exception is thrown by the runtime when code attempts to dereference a variable who's value is null. Therefore, if your method wants...
Read more >
Tired of Null Pointer Exceptions? Consider Using Java SE 8's ...
Creating Optional objects​​ of(soundcard); If soundcard were null, a NullPointerException would be immediately thrown (rather than getting a latent error once ...
Read more >
Java NullPointerException - Detect, Fix, and Best Practices
The NullPointerException can occur if the argument is being passed as null. The same method can be written as below to avoid  ......
Read more >
Interesting facts about null in Java - GeeksforGeeks
Since static methods are bonded using static binding, they won't throw Null pointer Exception.
Read more >
How to deal with NullPointerException in Java with Examples
NullPointerException in Java is nothing but an error or precisely an exception that occurs if we tried to perform any operation on an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found