Bug 563617 - ElementsImpl.getConstantExpression does not correctly quote strings
Summary: ElementsImpl.getConstantExpression does not correctly quote strings
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 4.16   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Generic inbox for the JDT-APT component CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-27 04:03 EDT by Matthew Wilson CLA
Modified: 2024-05-09 04:16 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Wilson CLA 2020-05-27 04:03:56 EDT
The JavaDoc of javax.lang.model.util.Elements.getConstantExpression(Object) says that the text returned should be "in a form suitable for representing the value in source code".  For strings, one would assume that would include escaping relevant characters -- e.g. "'\ and control characters.

The javac implementation does the quoting correctly.

The Eclipse implementation in ElementImpl does not.

https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tree/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java

		} else if (value instanceof String) {
			StringBuilder builder = new StringBuilder();
			builder.append('\"').append(value).append('\"');
			return String.valueOf(builder);
		}

I believe that the javac implementation is correct according to the specification.

I can attach a patch if it's useful.
Comment 1 Eclipse Genie CLA 2022-05-19 06:31:23 EDT
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.
Comment 2 Eclipse Genie CLA 2024-05-09 04:09:20 EDT
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.
Comment 3 Jay Arthanareeswaran CLA 2024-05-09 04:16:49 EDT
Well, this is sad that we didn't respond to this sooner.

@Mathew, if the bug is still relevant and offer to fix is available, I can take a look at the patch.