When fatal warnings set Java ones are also shown as errors
Closed this issue ยท 10 comments
With this configuration:
val moduleB = project
.in(file("moduleB"))
.settings(
scalaVersion := "3.3.3",
scalacOptions ++= Seq(
"-Xfatal-warnings"
),
javacOptions ++= Seq(
"-Xlint:unchecked"
)
)
and this file:
src/main/java/com/example/Service.java:
package com.example;
import java.util.List;
public class Service {
void create(List<Object> args) {
var second = (java.util.Optional<String>) args.get(2);
System.out.println(second);
}
}
Bloop will show the cast warning as error.
This is caused by the fact that we actually turn fatal warnings off to get all the artifacts compiler, we later upgrade diagnostics to errors. We probably don't check the source of them.
@tgodzik Would you mind if I took a stab at this one?
Sure! We should probably filter Java files around
Hi @tgodzik I'm having trouble reproducing this issue.
I'm currently running bloop version bloop v1.5.17
. Using the set up shared above I see only a warning:
/home/edmisml/programming/scala/bug_repros/bloop_2341/moduleB/src/main/java/com/example/Service.java:8: warning: [unchecked] unchecked cast
var second = (java.util.Optional<String>) args.get(2);
^
required: Optional<String>
found: Object
1 warning.
I created a simple sbt project:
- build.sbt :
resolvers += "scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/"
ThisBuild / scalaVersion := "2.13.14"
name := "hello-world"
organization := "ch.epfl.scala"
version := "1.0"
scalacOptions ++= Seq(
"-Xfatal-warnings"
)
javacOptions ++= Seq(
"-Xlint:unchecked"
)
- src/main/scala/Main.scala
import com.example.Service
object Main extends App {
val service = new Service()
service.create(List("").asInstanceOf[java.util.List[Object]])
println("Hello, World!")
}
- src/main/java/com/example/Service.java
package com.example;
import java.util.List;
public class Service {
String aaa = 123;
public void create(List<Object> args) {
var second = (java.util.Optional<String>) args.get(2);
System.out.println(second);
}
}
And it seems to repro in Metals via BSP. The only thing I see is that the Java warning is not show neither as error nor as warning in the CLI if there is no additional actual error.
I see. Thanks for sharing that. Weirdly with this project setup I still don't see the unchecked warning being reflected as an error in metals via BSP (I'm using the vscode extension and am looking at the "output" logs view) -- this is true regardless if there are additional errors in the java file. e.g.
/home/edmisml/programming/scala/bug_repros/bloop_2341/src/main/java/com/example/Service.java:7: error: incompatible types: int cannot be converted to String
String aaa = 123;
^
/home/edmisml/programming/scala/bug_repros/bloop_2341/src/main/java/com/example/Service.java:9: warning: [unchecked] unchecked cast
var second = (java.util.Optional<String>) args.get(2);
^
required: Optional<String>
found: Object
1 error
1 warning.
Here is my sample project. It should be identical to what you shared above except I had to use the jdk.CollectionConverters
else I was getting a different error.
You can check the bloop configuration files inside .bloop to see if they indeed have fatal warnings set
Fatal warnings are set in the bloop settings JSON file. I'm not sure what's going on. I tried cloning this repo mentioned in #6348 and the cast error still only shows as a warning in my metals output.
I've tried including "fatal warnings" (e.g. incomplete pattern matching) within scala files that are in the same project with the java file with the unchecked cast but it still only shows as a warning. I want to help but there isn't much to go off of if I can't reproduce it locally.
You could try writing a test and see if it reproduces there or on the CI.
But I can't really see how this would not reproduce, I'm put of ideas.