Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Java 9 why is the output from System.getenv() incomplete in jshell?

I'm using Windows 10 and running the version of Java 9 released by Oracle yesterday.

If I open a jshell and enter System.out.println(System.getenv()) the output is as expected, as shown in the lower portion of the screen shot below.

However, if I simply enter System.getenv() there is a big chunk of data missing from the middle of the output. See the initial portion of the screen shot below. This appears to be a feature of jshell since in the screen shot below the ellipsis ("...") in the output from System.getenv() (within the second box with hand drawn yellow edges) exactly corresponds to the missing data.

The end portion for the environment variable CommonProgramFiles is missing, as is the start of the environment variable SPRING_HOME, and there are several other environment variables such as Path which are not shown at all.

enter image description here

(Some information in the screen shot has been blurred for privacy.)

Does anyone else see the same thing (or not), and does anyone have suggestions on why jshell is doing this?

like image 703
skomisa Avatar asked Sep 22 '17 22:09

skomisa


1 Answers

JShell does truncate some string results that are printed in the REPL. It doesn't effect the printing to the console however.

We can see the same thing happening running this:

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
List<Integer> x = IntStream.range(0,3000).mapToObj(Integer::valueOf).collect(Collectors.toList());
x

We will see the same truncation with the ellipsis occur in that output.

If we print the result:

System.out.println(x);

we don't see this.


This is user configurable. For example, we can create a custom format mode that allows up to 40,000 characters (an excessively high number which we will likely not encounter, so no truncation occurs).

/set mode mine normal -command
/set truncation mine 40000
/set feedback mine

This creates a new feedback mode called mine which inherits from the built in mode normal (there are apparently a lot of options, so we inherit from another mode so that we don't have to worry about setting everything). See /help /set mode for details.

The second command sets the truncation to 40000 characters. It is possible to configure this so that the truncation depends on what sort of thing is displayed. See /help /set truncation for details.

Finally, the last command here switches to this feedback mode. Now, any thing displayed in the console will no longer be truncated unless it exceeds 40,000 characters.

This link along with the official documentation and the help commands above helped with figuring this out in order to write this answer.


The normal mode shows up to 1,000 characters before truncation. Use /set truncation by itself to display the various truncation settings or /set truncation normal to display the settings for normal mode.

like image 125
Matthew Avatar answered Dec 28 '22 08:12

Matthew