Archived
This forum has been archived. Please start a new discussion on GitHub.
ICE_CONFIG not honored under Java in 3.3

joshmoore
Germany
in Bug Reports
I may be misunderstanding under what conditions ICE_CONFIG is used in Java, but the attached tests shows that what I think is a straight-forward usage does not work, while it does so in Python.
0
Comments
-
-
I tried using ICE_CONFIG with Ice 3.3 and java and it worked for me. However I may not be attempting to use it in the same way as you, as I was unable to access your attachment. How did you attach the file? It does not appear to have been done using the regular message attachment feature. Also, what version of Java are you using?0
-
Sorry about the attachment. For whatever reason, they don't seem to be working for me. Instead, here's a script file to run the whole test:
#!/bin/bash test -e "$CLASSPATH" || { echo "$CLASSPATH unfound. Set CLASSPATH to Ice-3.3.0.jar"; exit 1 } echo `uname -a` echo `java -version` echo ========================= rm -rf test mkdir test cat > test/iceconfigtest.cfg<<EOF omero.user=me EOF cat > test/iceconfigtest.java<<EOF public class iceconfigtest { public static void main(String[] args) { System.out.println("ENV:" + System.getenv("ICE_CONFIG")); Ice.InitializationData id = new Ice.InitializationData(); id.properties = Ice.Util.createProperties(); if ( args.length > 0 ) { for ( String arg : args ) { System.out.println("Loading: " + arg); id.properties.load( arg ); } } Ice.Communicator ic = Ice.Util.initialize( id ); try { String value = ic.getProperties().getProperty("omero.user"); System.out.println("ICE:" + value); assert "me".equals(value); } finally { ic.destroy(); } } } EOF cat > test/iceconfigtest.py<<EOF import Ice, os print "ENV: " + os.environ["ICE_CONFIG"] id = Ice.InitializationData() ic = Ice.initialize(id) value = ic.getProperties().getProperty("omero.user") print value assert value == "me" EOF cd test echo Compiling javac -cp $CLASSPATH iceconfigtest.java echo Passes with value on command line env ICE_CONFIG=iceconfigtest.cfg java -ea -cp $CLASSPATH:. iceconfigtest iceconfigtest.cfg echo Fails without. env ICE_CONFIG=iceconfigtest.cfg java -ea -cp $CLASSPATH:. iceconfigtest echo Also ok in Python env ICE_CONFIG=iceconfigtest.cfg python iceconfigtest.py
And output from three different machines:CLASSPATH=xxx/ice-3.3.0.jar ./ice_config.sh Linux gxxx 2.6.18-53.1.14.el5 #1 SMP Wed Mar 5 11:37:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux java version "1.6.0_06" Java(TM) SE Runtime Environment (build 1.6.0_06-b02) Java HotSpot(TM) 64-Bit Server VM (build 10.0-b22, mixed mode) ========================= Compiling Passes with value on command line ENV:iceconfigtest.cfg Loading: iceconfigtest.cfg ICE:me Fails without. ENV:iceconfigtest.cfg ICE: Exception in thread "main" java.lang.AssertionError at iceconfigtest.main(iceconfigtest.java:24) Also ok in Python ENV: iceconfigtest.cfg
CLASSPATH=xxx/ice-3.3.0.jar ./ice_config.sh Linux nxxx 2.6.23-gentoo-r8 #2 SMP Tue Feb 19 19:27:38 GMT 2008 x86_64 Intel(R) Xeon(R) CPU X5355 @ 2.66GHz GenuineIntel GNU/Linux java version "1.6.0_03" Java(TM) SE Runtime Environment (build 1.6.0_03-b05) Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode) ========================= Compiling Passes with value on command line ENV:iceconfigtest.cfg Loading: iceconfigtest.cfg ICE:me Fails without. ENV:iceconfigtest.cfg ICE: Exception in thread "main" java.lang.AssertionError at iceconfigtest.main(iceconfigtest.java:24) ...(missing Python)...
CLASSPATH=xxx/ice-3.3.0.jar ./ice_config.sh Darwin jxxx 8.11.1 Darwin Kernel Version 8.11.1: Wed Oct 10 18:23:28 PDT 2007; root:xnu-792.25.20~1/RELEASE_I386 i386 i386 java version "1.5.0_16" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-275) Java HotSpot(TM) Client VM (build 1.5.0_16-132, mixed mode, sharing) ========================= Compiling Passes with value on command line ENV:iceconfigtest.cfg Loading: iceconfigtest.cfg ICE:me Fails without. ENV:iceconfigtest.cfg ICE: Exception in thread "main" java.lang.AssertionError at iceconfigtest.main(iceconfigtest.java:24) Also ok in Python ENV: iceconfigtest.cfg me
0 -
This is not a bug in Ice. The issue is that you are using Ice.Util.createProperties() (ie with no args) to create the properties in your test. If you take a look at section 38.8.2 of the manual you will see the following:
"The parameter-less version of createProperties simply creates an empty property set. It does not check ICE_CONFIG for a configuration file to parse."
Change your test to use Ice.Util.createProperties(args) and you should get the behavior you expect.0 -
Thanks for looking into this, Dwayne.
It's also possible to comment out the call to createProperties completely and still have the test case fail. It's there for doing the manual loading, but I did test without it.
Is the expected behavior that ICE_CONFIG will only be checked when command-line-like arguments are explicitly passed into either Ice.Util.createProperties or an initialize method, i.e. not when using something like "Ice.Util.initialize()" If so, would you mind explaining the logic behind this for me? The behavior in Python where:import Ice ic = Ice.initialize()
does honor ICE_CONFIG seems more natural.
Thanks again,
~Josh.0 -
The behavior between python and java is indeed inconsistent. We are discussing internally how this should be fixed. That is, which language should be changed to act like the other. Thanks for bringing this to our attention.0
-
Hi Dwayne,
just another data point for your discussions. I was surprised that the two print methods returned different values:import Ice f = open("cfg","w") f.write("omero.host=hi\n") f.close() args1 = ["--Ice.Config=cfg"] args2 = list(args1) id = Ice.InitializationData() ic = Ice.initialize(args1,id) print "1:",ic.getProperties().getProperty("omero.host") id = Ice.InitializationData() id.properties = Ice.createProperties() id.properties.parseIceCommandLineOptions(args2) id.properties.parseCommandLineOptions("omero", args2) print id.properties ic = Ice.initialize(id) print "2:",ic.getProperties().getProperty("omero.host")
Reading the manual again, createProperties() is responsible for parsing ICE_CONFIG/Ice.Config, but I continually assume that it's Ice.initialize(), perhaps because of the simplicity of Python's Ice.initialize() doing everything.
Not a complaint, just pointing out where even Ice regular's can go afoul.
~J.0