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

Bug 449244

Summary: IField#getConstant() is wrong for String-valued fields
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: igor, jarthana
Version: 4.5   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug
Bug Depends on:    
Bug Blocks: 449241    

Description Markus Keller CLA 2014-10-29 15:51:04 EDT
Follow-up to bug 406836.

IField#getConstant() is wrong for String-valued fields. It always returns the initializer source, but it should either return a fully-parsed string or null. 

Examples:
	public final String now = "now is " + System.currentTimeMillis();
	public final String hello = "Hello\n";
	public final String helloWorld = "Hello\n" + "World";

According to the current restrictions stated in the API, I'd expect:
- for 'now': null
- for 'hello': 'Hello!'
- for 'helloWorld': null
Comment 1 Jay Arthanareeswaran CLA 2014-10-31 07:18:23 EDT
(In reply to Markus Keller from comment #0)
> - for 'now': null
> - for 'hello': 'Hello!'
> - for 'helloWorld': null

The '!' is a typo, right?
Comment 2 Markus Keller CLA 2014-10-31 08:02:01 EDT
(In reply to Jayaprakash Arthanareeswaran from comment #1)
> > - for 'hello': 'Hello!'
> The '!' is a typo, right?

No, the typo is in the declaration. It should be:

	public final String hello = "Hello\u0021";

I included the special character to ensure the implementation doesn't just copy the source but properly parses the escapes and removes the double-quotes. When I wrote the expected values, I realized that \n is hard to write on one line, so I changed it but forgot to update the declaration as well.

Thanks for spotting!
Comment 3 Markus Keller CLA 2015-08-24 06:25:07 EDT
*** Bug 475481 has been marked as a duplicate of this bug. ***
Comment 4 Eclipse Genie CLA 2019-02-26 11:02:02 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.