GNU bug report logs -
#75440
dejagnu does not like java.io.Console of OpenJDK >= 22
Previous Next
To reply to this bug, email your comments to 75440 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-dejagnu <at> gnu.org
:
bug#75440
; Package
dejagnu
.
(Wed, 08 Jan 2025 17:25:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Chris Nospam <chris21k <at> gmx.de>
:
New bug report received and forwarded. Copy sent to
bug-dejagnu <at> gnu.org
.
(Wed, 08 Jan 2025 17:25:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Dear maintainers,
starting with OpenJDK Java 22 java programs using java.io.Console cannot be testet with dejagnu any more. With JDK 21 it works like a charm.
I belive it has to do with excape sequences that are not filtered out correctly or similar. I am using dejagnu 1.6.3-1, debain package under Ubuntu 24.04.
For an easy reproduction of the bug I have attached a simple example simple.zip. Just unpack it and execute exectest.sh. Be sure to update JAVA_HOME in this script to a jdk 22 or 23 installation.
In testsuite/simple.log some escape sequences are shown were no one are expected:
^[[?1h^[=^[[?2004hhello
^[[?1l^[>^[[?1000l^[[?2004lhello
The attached simple echo example works after simply commenting the lines 13-14 (using Console) and uncommenting lines 16-17 (using BufferedReader) in testsuite/simple.sh.
Alternatively it also works by passing -Djdk.console=java.base to the jvm (1st line in exectest.sh), to trigger the old implementation in JDK.
#!/usr/bin/env -S java --source 23
// #!/usr/local/java/jdk-23.0.1/bin/java --source 23 -Djdk.console=java.base
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ConsoleTest {
public static void main(String[] args) throws IOException {
System.out.print("prompt> ");
java.io.Console c = System.console();
String input = c.readLine();
// BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// String input = in.readLine();
System.out.println(input);
System.out.println("prompt> ");
}
}
It has something to do with the change of the Java default Console provider to JLine in Java 22.
https://bugs.openjdk.org/browse/JDK-8309141
However, as Java Console works everywhere else (windows/linux console/bash/EclipseIDE internal "console"/IntelliJ internal "console") as far I can see, it seems to be something special with dejagnu.
Thanks for dejagnu, maintaining it, and your help,
Chris
[simple.zip (application/x-zip-compressed, attachment)]
Information forwarded
to
bug-dejagnu <at> gnu.org
:
bug#75440
; Package
dejagnu
.
(Thu, 09 Jan 2025 01:56:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 75440 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 1/8/25 10:44, Chris Nospam via Bug-dejagnu via wrote:
> Dear maintainers,
>
> starting with OpenJDK Java 22 java programs using java.io.Console cannot be testet with dejagnu any more. With JDK 21 it works like a charm.
This is a JVM bug or misfeature. We have recently had similar problems
with MinGWGCC tested under Wine. In that case, it was a consequence of
Wine's new support for Windows quasi-ptys.
> I belive it has to do with excape sequences that are not filtered out correctly or similar. I am using dejagnu 1.6.3-1, debain package under Ubuntu 24.04.
DejaGnu does not and cannot filter escape sequences. Expect matches the
patterns it is given. You can write patterns in your testsuite that
accommodate or even verify escape sequences from the program under test.
> For an easy reproduction of the bug I have attached a simple example simple.zip. Just unpack it and execute exectest.sh. Be sure to update JAVA_HOME in this script to a jdk 22 or 23 installation.
>
> In testsuite/simple.log some escape sequences are shown were no one are expected:
> ^[[?1h^[=^[[?2004hhello
> ^[[?1l^[>^[[?1000l^[[?2004lhello
The JVM IO facilities are inserting escape sequenceswithout your program
calling for them. This is a JVM bug or misfeature that Expect (on which
DejaGnu is built) exposes.
> The attached simple echo example works after simply commenting the lines 13-14 (using Console) and uncommenting lines 16-17 (using BufferedReader) in testsuite/simple.sh.
> Alternatively it also works by passing -Djdk.console=java.base to the jvm (1st line in exectest.sh), to trigger the old implementation in JDK.
>
> #!/usr/bin/env -S java --source 23
> // #!/usr/local/java/jdk-23.0.1/bin/java --source 23 -Djdk.console=java.base
>
> import java.io.BufferedReader;
> import java.io.IOException;
> import java.io.InputStreamReader;
>
> public class ConsoleTest {
>
> public static void main(String[] args) throws IOException {
> System.out.print("prompt> ");
>
> java.io.Console c = System.console();
> String input = c.readLine();
>
> // BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
> // String input = in.readLine();
>
> System.out.println(input);
> System.out.println("prompt> ");
> }
>
> }
First, think about what your program actually does compared to what your
testsuite code expects it to do. Examine the message produced at the
end of the test run in simple.log. In fact, that message is produced
*after* echo.exp has completed. Where does that message come from?
(You will benefit far more from the lesson if you find it for yourself
than if I tell you. There is only one place in your testsuite that can
emit that message.)
Second, the inability to send text to the program under test is not a
failure: it is an error and probably an UNRESOLVED test. A block that
is executed as a result of catching a Tcl error probably should be
invoking "error" or possibly "unresolved", not "fail" or even "pass"
(unless you are testing an error condition).
Third, Tcl interpolates backslash escapes in double-quoted strings. You
will need to double (some of) the backslashes and/or review re_syntax(n)
for Tcl regexp syntax.
Fourth, think about simple_test could actually fail. That depends on
what you are trying to do, but any "pass" should have a corresponding
"fail" somewhere.
(Most of the above refers to Expect code in your
testsuite/config/default.exp file.)
> It has something to do with the change of the Java default Console provider to JLine in Java 22.
> https://bugs.openjdk.org/browse/JDK-8309141is is not special with DejaGnu; we have recently had similar issues with
> Wine, encountered while testing mingw32 builds on *nix hosts
> However, as Java Console works everywhere else (windows/linux console/bash/EclipseIDE internal "console"/IntelliJ internal "console") as far I can see, it seems to be something special with dejagnu.
No, the problem is with the JVM and/or your programs and scripts. It
appears to work everywhere else because those escape sequences either
perform terminal control functions or are ignored. You can write
regexps that will optionally match and discard the escape sequences.
Expect exposes this issue because it is strict about matching exactly
what you tell it to match.
-- Jacob
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-dejagnu <at> gnu.org
:
bug#75440
; Package
dejagnu
.
(Tue, 14 Jan 2025 13:41:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 75440 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/html, inline)]
[simple.zip (application/x-zip-compressed, attachment)]
Information forwarded
to
bug-dejagnu <at> gnu.org
:
bug#75440
; Package
dejagnu
.
(Tue, 14 Jan 2025 16:05:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 75440 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/html, inline)]
[simple.zip (application/x-zip-compressed, attachment)]
Information forwarded
to
bug-dejagnu <at> gnu.org
:
bug#75440
; Package
dejagnu
.
(Wed, 15 Jan 2025 04:01:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 75440 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
[actually you had the new ZIP file on the first message; I can tell
because the Java program has a loop now]
[also, traditional email discussions use inline responses with a summary
or further commentary at the end after the response to the last quote;
please refrain from top-posting if possible]
On 1/14/25 05:12, Chris Nospam wrote:
> Dear Jacob,
> sorry for my late reply and thanks for your rapid and detailed answer.
> Also I am sorry for the faulty default.exp, it was a quick & dirty
> version to trigger the bug and only a short snipped of my real project.
That is a new piece of information and I have found other issues that I
would normally overlook in a small testsuite, but will make problems for
you in a large testsuite. More on this below.
> It should only show the problem with the first echo. However, I have
> enhanced it somehow now, see the attachement.
I see that the new version of your sample program now contains a loop
instead of exiting unconditionally after the first input. This produces
a more useful error, complete with a backtrace explaining how you got
there. (The framework will call a "${tool}_exit" procedure during
per-target cleanup if it exists.)
Unfortunately, coordinating the exit of an interactive program is
tedious because Expect will close the channel upon reading EOF and
expecting on a closed channel throws an error. (This should be a hint
towards one way to solve the problem.)
You should try using runtest's --debug option, which will cause Expect
to write considerable information about its operation to the "dbg.log"
file. That log is particularly useful when seeking to understand why
patterns do or do not match.
> > Tcl interpolates backslash escapes in double-quoted strings
> I changed now \r\n to \\r\\n in all regular expressions.
It is important to understand what Tcl will do with your code, although
that particular item "happens to work" either way. (Literal carriage
return and newline match themselves in Tcl regexps in normal syntax, but
can make dbg.log harder to read.)
> Please forgive me, I am not an expert in expect script but I try to do
> my best. I would be happy if you could give me some (direct) advices.
You still need to think about what your test results mean. DejaGnu has
other status codes because simple PASS/FAIL does not really work in the
real world. You should be using "perror" and "unresolved" to report
inabilities to run the test program.
More concretely, simple_start should clear the prompt_error flag upon
receiving a prompt and should use "perror" instead of "send_user" to
report failure to spawn the program.
Similarly, if the prompt_error flag is set, "simple_test" should emit an
UNRESOLVED result (using the "unresolved" procedure) before returning,
because the test was not performed due to a run-time condition.
The important rule here is that the total number of test results should
not change.
Tcl allows optional arguments; you can replace the dispatch logic around
"simple_test" by using {proc simple_test {expr result {comment ""}}
...} (The outer-most brace pair denotes a Tcl code fragment.)
Tcl procedure arguments are also ordinary local variables, so you can do
{ if {$comment ne ""} {set comment "\[$comment\]"} } in a combined
"simple_test" if you want.
Think carefully about what you are doing with the "answer" global
variable. It should probably be an argument, if not the "result"
argument that you already have.
Lastly, your "if" conditionals should usually be in braces; this allows
the Tcl compiler to produce more efficient bytecode.
> I will open a corresponding issue at https://bugreport.java.com and
> report back a link. Hopefully, they will look into/fix it and not only
> dismiss that using dejagnu is an edge case.
Hopefully they will at least recognize that a transparent console mode
is important and ensure that one remains supported.
-- Jacob
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-dejagnu <at> gnu.org
:
bug#75440
; Package
dejagnu
.
(Mon, 20 Jan 2025 10:39:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 75440 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/html, inline)]
This bug report was last modified 145 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.