Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 333626

Summary: NLS.Bind(String string,String[] params) does not retrieve right string
Product: [Eclipse Project] Equinox Reporter: manasa <manasa.priya.c>
Component: FrameworkAssignee: equinox.framework-inbox <equinox.framework-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: pwebster, remy.suen, tjwatson
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description manasa CLA 2011-01-06 02:12:17 EST
Build Identifier: Build id: I20100608-0911

We are using NLS.Bind() in our globalization to bind the string which contains parameters with the actual string values.

NLS.bind(parameterizedString, params), when called with following parameters, 
parameterizedString - " Unexpected Operator: {0}", 
params - Test0
returns -  "Unexpected Operator: Test0" where the arguement is replaced by the given string.This is the expected value.

The same method when called with,
parameterizedString - "Couldn't convert ''{0}'' to int"
params - Test0
returns -  "Couldnt convert {0}' to int" which is not the expected string.
Ideally it should have been, "Couldn't convert 'Test0' to int", where the double apostrophe's are replaced by the given string within apostrophes.

Reproducible: Always

Steps to Reproduce:
1.Call method NLS.Bind(String string, String[] params) in Messages.java file which gets created during externalization of strings.
2.Arguements as, (Couldn't convert ''{0}'' to int, new String[]{"Test0"}
3.Will give a result "Couldnt convert {0}' to int"
Comment 1 Thomas Watson CLA 2011-01-06 08:59:42 EST
This test seems to be invalid because you do not double '' for Couldn't when trying to format the message.  Similar results are shown by MessageFormat.  See the following test which tries both NLS and MessageFormat with "Couldn't" and "Couldn''t"


// must double '' for Couldn't
String test = NLS.bind("Couldn''t convert ''{0}'' to int", 
                    new String[] {"Test0"});
assertEquals("Wrong result", "Couldn't convert 'Test0' to int", test);

test = MessageFormat.format("Couldn''t convert ''{0}'' to int", 
                    new String[] {"Test0"});
assertEquals("Wrong result", "Couldn't convert 'Test0' to int", test);

// See what happens if not '' for Couldn't
test = NLS.bind("Couldn't convert ''{0}'' to int",
            new String[] {"Test0"});
assertEquals("Wrong result", "Couldnt convert {0}' to int", test);

test = MessageFormat.format("Couldn't convert ''{0}'' to int", 
            new String[] {"Test0"});
assertEquals("Wrong result", "Couldnt convert '{0}' to int", test);

The only questionable behavior difference is MessageFormat seems to recover a bit differently than NLS because it uses '{0}' where NLS is missing the first qoute {0}'