I have following problem in Java:

This works as it should:

xyz.setUserValue("ABC", "file_xyz.abc");

But this doesn't:

String test = "file_" + VariableXYZ.toLowerCase() + ".abc";
System.out.println(test);
xyz.setUserValue("ABC", test);


--> output of println(test) ==> file_xyz.abc
The weird thing ist that it worked before but from one moment to another it doesn't. Java bug? - Any Ideas?

Thanks beforehand!!

有帮助吗?

解决方案

No it is not a Java bug.

It is not possible to say what actually is causing this, but there is no chance it is a Java bug.

If you explained the context better and showed us the code for the setUserValue method, we could possibly come up with plausible theories. (An SSCCE would be ideal, but I strongly suspect that you won't be able to code one that reliably demonstrates the problem ....)


OK given this:

public static String setUserValue(String key, String value) { 
    String oldValue = getUserProperties().getProperty(key);
    getUserProperties().setProperty(key, value); 
    return oldValue;
}

... then assuming that the "properties" objects are instances of Properties, the most likely explanations are:

  • something is causing getUserProperties() to return a different object in the first and second calls,
  • something else is modifying the Properties object between the first and second call,
  • the Properties object starts out with a different value for "ABC" than that you are expecting, or
  • something else is changing the property back to its original value; e.g. by reloading the properties from the source file.

Or maybe there is an exception that you are not telling us about ... or have squashed. Or maybe you are comparing Strings the wrong way (using ==) and that is confusing you / your program.

Or maybe you've got a problem with the way that you build and/or deploy stuff.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top