Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333626 - NLS.Bind(String string,String[] params) does not retrieve right string
Summary: NLS.Bind(String string,String[] params) does not retrieve right string
Status: RESOLVED INVALID
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Framework (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: equinox.framework-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-06 02:12 EST by manasa CLA
Modified: 2011-01-06 08:59 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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}'