I’m in trouble with some simple Java code :
// the env var is set
public final String METACHEK_pref = System.getenv().get("MCHK_DIR");
// the env var should be :
public String tempMP = "/disk3/METACHECK/Metacheck/metachek";
System.out.println("#1:"+METACHEK_pref+File.separator+"metachek");
System.out.println("#2:"+tempMP+File.separator+"metachek");
which prints:
#1:/metachekTACHECK/Metacheck/metachek
#2:/disk3/METACHECK/Metacheck/metachek/metachek
I’ve tried that code in different OS and just one solaris have this problem. And, of course, the code has to work on this specific server.
I’ve no idea to where to check if it’s some strange parameters to set in an hidden conf file.
Anyone has an idea what’s going on? Why the concat has evolved to an insert command?
EDIT:
I’ve created another jar with this code:
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String METACHEK_pref = new String(System.getenv().get("MCHK_DIR").toString());
String tempMP = "/disk3/METACHECK/Metacheck/metachek";
System.out.println("#1:"+METACHEK_pref);
System.out.println("#2:"+METACHEK_pref+File.separator+"metachek");
System.out.println("#3:"+tempMP+File.separator+"metachek");
}
}
and this is the output:
#1:/disk3/METACHECK/Metacheck/metachek /metachek/METACHECK/Metacheck/metachek #3:/disk3/METACHECK/Metacheck/metachek/metachek
See how the #2 disappear?
I’m fairly sure that the
MCHK_DIRenvironment variable ends in a CR character (carriage return, better known as the-first-part-of-CRLF).This explains pretty exactly what you experience: the visible part of
MCHK_DIRis printed and the cursor is placed at the beginning of the line. Then the thing you appended is printed (overwriting the start of the visibleMCHK_DIRtext).How this occurs is somewhat of a mystery to me, as most ways to set an environment variable don’t make it easy to append a whitespace character (such as CR).
To check if this is indeed the case, iterate over the characters of your variable and print their values: