[QFJ-642] SessionSettings getSessionProperties(Foo, true) merges the actual settings into the defaults Created: 17/Oct/11  Updated: 15/Nov/12  Resolved: 19/Oct/11

Status: Closed
Project: QuickFIX/J
Component/s: Engine
Affects Version/s: 1.5.0, 1.5.1
Fix Version/s: 1.5.2

Type: Bug Priority: Major
Reporter: Mate Varga Assignee: Laurent Danesi
Resolution: Fixed Votes: 0
Labels: None


 Description   

If you do the following in your code:

Properties sessionProperties = sessionSettings.getSessionProperties(sessionID, true);

Then after executing the previous statement, sessionSettings.getDefaultProperties() will return the original default properties MERGED WITH the session properties specified under the sessionID, which is completely wrong. The reason lies in SessionSettings.java (comments inlined):

public Properties getSessionProperties(SessionID sessionID, boolean includeDefaults) throws ConfigError {
final Properties p = sections.get(sessionID);
if (p == null)

{ throw new ConfigError("Session not found"); }

if (includeDefaults)

{ final Properties mergedProperties = sections.get(DEFAULT_SESSION_ID); // THIS RETURNS A REFERENCE, NOT A COPY!! mergedProperties.putAll(p); /// THAT IS COMPLETELY WRONG, AS THIS MODIFIES THE ORIGINAL MAP CONTENTS return mergedProperties; }

else

{ return p; }

}

The proper solution would be to create a new Properties object and initialise it using the Properties object returned by sections.get().



 Comments   
Comment by Mate Varga [ 18/Oct/11 ]

// Fix:

public Properties getSessionProperties(SessionID sessionID, boolean includeDefaults) throws ConfigError {
final Properties p = sections.get(sessionID);
if (p == null)

{ throw new ConfigError("Session not found"); }


if (includeDefaults)

{ final Properties mergedProperties = new Properties(); mergedProperties.putAll(sessionSettings.getDefaultProperties()); mergedProperties.putAll(p); return mergedProperties; }


else

{ return p; }


}

Comment by Laurent Danesi [ 19/Oct/11 ]

committed rev #1054

Generated at Sat Nov 23 07:35:10 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.