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

Part of Javac diagnostic messages are hidden #523

Closed
retronym opened this issue Apr 5, 2018 · 3 comments
Closed

Part of Javac diagnostic messages are hidden #523

retronym opened this issue Apr 5, 2018 · 3 comments
Assignees
Milestone

Comments

@retronym
Copy link
Member

retronym commented Apr 5, 2018

The following code in DiagnosticReporter:

private def fixedDiagnosticMessage(d: Diagnostic[_ <: JavaFileObject]): String = {
def getRawMessage = d.getMessage(null)
def fixWarnOrErrorMessage = {
val tmp = getRawMessage
// we fragment off the line/source/type report from the message.
// NOTE - End of line handling may be off.
val lines: Seq[String] =
tmp.split(END_OF_LINE_MATCHER) match {
case Array(head, tail @ _*) =>
val newHead = head.split(":").last
newHead +: tail
case Array(head) =>
head.split(":").last :: Nil
case Array() => Seq.empty[String]
}
lines.mkString(EOL)
}
d.getKind match {
case Diagnostic.Kind.ERROR | Diagnostic.Kind.WARNING | Diagnostic.Kind.MANDATORY_WARNING =>
fixWarnOrErrorMessage
case _ => getRawMessage
}
}

d.getMessage(null) = """module not found: acme.b"""
PositionImpl(d).toString = "/Users/jz/code/javafileman/acme.a/src/main/java/module-info.java:3"

And runs the result of getMessage through a regex translation, documented to remove the source file name and line number. But they don't exist in that string, and instead we strip half of the message:

fixWarnOrErrorMessage = " acme.b"

Which is reported to the user as:

[warn] /Users/jz/code/javafileman/acme.a/src/main/java/module-info.java:3:1:  acme.b
[warn]     exports acme.a.shared to acme.b;

I'm using Java 10, not sure yet if the behaviour of getMessage has changed, or it this is just a long standing bug that you only notice when an Java error or warning contains ':'

@retronym
Copy link
Member Author

retronym commented Apr 5, 2018

It's an old bug:

⚡ java -version
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-jenkins_2017_07_27_21_17-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

⚡ sbt compile
[info] Loading settings from dirtymoney.sbt,gpg.sbt,idea.sbt ...
[info] Loading global plugins from /Users/jz/.sbt/1.0/plugins
[info] Loading project definition from /private/tmp/javac-diagnostic/project
[info] Set current project to javac-diagnostic (in build file:/private/tmp/javac-diagnostic/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] Compiling 1 Java source to /private/tmp/javac-diagnostic/target/scala-2.12/classes ...
[error] /private/tmp/javac-diagnostic/src/main/java/example/Test.java:4:1:  C.D
[error]         D.this.toString();
[error] (Compile / compileIncremental) javac returned non-zero exit code
[error] Total time: 0 s, completed 05/04/2018 12:52:16 PM

⚡ cat src/main/java/example/Test.java
class C {
    class D {}
    void test() {
        D.this.toString();
    }
}

⚡ javac src/main/java/example/Test.java
src/main/java/example/Test.java:4: error: not an enclosing class: C.D
        D.this.toString();
         ^
1 error

@dwijnand
Copy link
Member

dwijnand commented Apr 5, 2018

is this also #520 (which is as known as #376)?

@retronym
Copy link
Member Author

retronym commented Apr 5, 2018

You'd need to have a single javac error message line, ending in a :. Even then, I think you'd see [error] <blank>'. So I'd bet that's a different issue.

@dwijnand dwijnand added this to the 1.1.4 milestone Apr 5, 2018
@dwijnand dwijnand closed this as completed Apr 5, 2018
dwijnand added a commit to dwijnand/zinc that referenced this issue Apr 5, 2018
dwijnand added a commit to dwijnand/zinc that referenced this issue Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants