Skip to content

JndiTemplate could promote default properties to first-level before initialization [SPR-4135] #8814

@spring-projects-issues

Description

@spring-projects-issues

Jared Stehler opened SPR-4135 and commented

I recently debugged an issue involving the JndiTemplate and the java.util.Properties object, which I think warrants either a new minor enhancement in the jndiTemplate, or some javadoc comments alerting clients to the dangers of using default properties when trying to initialize an InitialContext.

I have a JndiConnectionRef object, with a static Properties object loaded from a file on startup, containing all of the special CORBA properties required for a Sun JVM to interact successfully with an IBM JVM, except for the actual provider URL, which differs for each object. In the object's constructor, I was creating a new Properties object, using the Properties( Properties defaults ) constructor, which I saw was setting default properties for this object, then adding my additional providerURL property and sending it off to the JndiTemplate for initialization.

The problem is that while JndiTemplate takes a java.util.Properties object for configuration, all of the implementations of the InitialContext, NamingManager deal with Hashtable, the superclass of Properties, using Hashtable.get() to retrieve environment values. This bypasses defaults in the properties object, since all of the code to failover to default values exists in Properties.getProperty(), and java.util.Properties does not override Hashtable.get for some reason.

Now I solved this issue by changing my code to create a new Properties object and then call putAll( myDefaultProperties ), but it seems like I could have avoided my need for debugging this issue with either a warning in the jndiTemplate constructor / setEnvironment method javadocs indicating that defaults on the given Properties object will be ignored, or perhaps some logic in setEnvironment which 'promotes' all default properties which do not have an explicitly defined value to 'top-level' values before calling new InitialContext(getEnvironment()).

Do you think this is the appropriate place to post this request, or should I post to bugs.sun.com requesting they override Hashtable.get() in java.util.Properties to properly delegate to the logic in getProperty()?


Affects: 2.0.7

Backported to: 2.0.8

Metadata

Metadata

Assignees

Labels

status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions