Project

General

Profile

Bug #3874

ptolemy.util.StringUtilities.mergePropertiesFile() deletes properties

Added by Daniel Crawl over 10 years ago. Updated about 10 years ago.

Status:
Resolved
Priority:
Normal
Category:
general
Target version:
Start date:
03/09/2009
Due date:
% Done:

0%

Estimated time:
Bugzilla-Id:
3874

Description

mergePropertiesFile() appears to delete properties, including java.home and java.class.path.

Note that this method will only be run if $PTII/ptolemy/lib/ptII.properties exists, which is created by running $PTII/configure.

ptII.properties (2.16 KB) ptII.properties Daniel Crawl, 03/10/2009 11:03 AM

History

#1 Updated by Christopher Brooks over 10 years ago

Hmm, I can't reproduce this.

The following Tcl Code works as expected
% java::call ptolemy.util.StringUtilities mergePropertiesFile
% set property [java::call ptolemy.util.StringUtilities getProperty java.class.path]
/Users/cxh/ptII:/Users/cxh/ptII/lib/diva.jar:/Users/cxh/ptII/ptolemy/distributed/jini/jar/jini-core.jar:/Users/cxh/ptII/ptolemy/distributed/jini/jar/jini-ext.jar:/Users/cxh/ptII/ptolemy/distributed/jini/jar/sun-util.jar:/Users/cxh/ptII/lib/ptCal.jar:/Users/cxh/ptII/lib/java_cup.jar:/Users/cxh/ptII/lib/chic.jar:/Users/cxh/ptII/lib/ptcolt.jar:/Users/cxh/ptII/lib/sootclasses.jar:/Users/cxh/ptII/lib/jasminclasses.jar:/Users/cxh/ptII/lib/polyglotclasses-1.3.2.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/../Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/jce.jar:/Users/cxh/ptII/lib/ptjacl.jar:/Users/cxh/ptII/vendors/misc/joystick/Joystick.jar:/Users/cxh/ptII/vendors/jython/jython.jar:/Users/cxh/ptII/vendors/sun/jxta/jxta.jar:/Users/cxh/ptII/vendors/sun/jxta/log4j.jar:/Users/cxh/ptII/vendors/sun/jxta/beepcore.jar:/Users/cxh/ptII/vendors/sun/jxta/jxtasecurity.jar:/Users/cxh/ptII/vendors/sun/jxta/cryptix-asn1.jar:/Users/cxh/ptII/vendors/sun/jxta/cryptix32.jar:/Users/cxh/ptII/vendors/sun/jxta/jxtaptls.jar:/Users/cxh/ptII/vendors/sun/jxta/minimalBC.jar:/gdk.jar:/Users/cxh/ptII/ptolemy/actor/lib/database/mysql-connector-java-5.1.6-bin.jar:/Users/cxh/ptII/ptolemy/actor/lib/database/ojdbc5.jar:/Users/cxh/ptII/ptolemy/actor/ptalon/antlr/antlr.jar::/Users/cxh/ptII/lib/mapss.jar:/Users/cxh/ptII/lib/saxon8.jar:/Users/cxh/ptII/lib/saxon8-dom.jar:/Users/cxh/ptII/ptolemy/domains/ptinyos/lib/jdom.jar:/Users/cxh/ptII/ptolemy/domains/ptinyos/lib/nesc.jar
% set property [java::call ptolemy.util.StringUtilities getProperty java.home]
/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home

mergePropertiesFile() looks like:

/** Merge the properties in lib/ptII.properties with the current
     *  properties.  lib/ptII.properties is searched for in the
     *  classpath.  The value of properties listed in
     *  lib/ptII.properties do not override properties with the same
     *  name in the current properties.
     *  @exception IOException If thrown while looking for the
     *  $CLASSPATH/lib/ptII.properties file.
*/
public static void mergePropertiesFile() throws IOException {
Properties systemProperties = System.getProperties();
Properties newProperties = new Properties();
String propertyFileName = "$CLASSPATH/lib/ptII.properties";
// FIXME: xxxxxxCLASSPATHxxxxxx is an ugly hack
URL propertyFileURL = FileUtilities.nameToURL(
"xxxxxxCLASSPATHxxxxxx/lib/ptII.properties", null, null);
if (propertyFileURL == null) {
throw new IOException("Could not find " + propertyFileName);
}
newProperties.load(propertyFileURL.openStream());
// systemProperties is a HashSet, so we merge in the new properties.
newProperties.putAll(systemProperties);
System.setProperties(newProperties);
// FIXME: This should be logged, not printed.
//System.out.println("Loaded " + propertyFileURL);
}

What does your lib/ptII.properties file look like?

#3 Updated by Daniel Crawl over 10 years ago

I've attached the generated lib/ptII.properties file.

Can you start Kepler if that file exists? On both mac and linux, I cannot. I haven't tried windows.

#4 Updated by Daniel Crawl about 10 years ago

I just saw this bug occur on windows xp: if $PTII/lib/ptII.properties exists, Kepler won't start:

[run] Caused by: java.lang.Error: Can't find java.home ??

#5 Updated by Christopher Brooks about 10 years ago

Ok, I can replicate a problem in Kepler under Windows XP

If I do:
cp $PTII/lib/ptII.properties ../ptolemy/lib
Then "ant run" fails with messages about missing fonts.

#6 Updated by Christopher Brooks about 10 years ago

Fixed. I'm not sure what the cause is here, I can't get a small test to fail.
Basically, we read the system properties and create a java.util.Properties, see
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html

We then read in the properties file and then call putAll and merge in
the previous system properties.

public static void mergePropertiesFile() throws IOException {
Properties systemProperties = System.getProperties();
Properties newProperties = new Properties();
String propertyFileName = "$CLASSPATH/lib/ptII.properties";
// FIXME: xxxxxxCLASSPATHxxxxxx is an ugly hack
URL propertyFileURL = FileUtilities.nameToURL(
"xxxxxxCLASSPATHxxxxxx/lib/ptII.properties", null, null);
if (propertyFileURL == null) {
throw new IOException("Could not find " + propertyFileName);
}
newProperties.load(propertyFileURL.openStream());
// systemProperties is a HashSet, so we merge in the new properties.
newProperties.putAll(systemProperties);
System.setProperties(newProperties);
}

For some reason, in Kepler, this results in a partially truncated set of
properties. I suspect a threading bug.

Happily, if I instantiate newProperties with:
Properties newProperties = new Properties(systemProperties);

and remove the putAll() call, then the problem goes away.

I'm not sure why this makes a difference, but it does.

#7 Updated by Redmine Admin over 6 years ago

Original Bugzilla ID was 3874

Also available in: Atom PDF