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

Bug 353205

Summary: [GANTT] IllegalArgumentException when event name contains special characters
Product: z_Archived Reporter: Wim Jongman <wim.jongman>
Component: NebulaAssignee: Makenna Fish <makenna.g.kai>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: makenna.g.kai
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/73675
https://git.eclipse.org/c/nebula/org.eclipse.nebula.git/commit/?id=37adf5c2444c1b74f93be86cc347fd11daa83cc4
Whiteboard:

Description Wim Jongman CLA 2011-07-27 09:38:58 EDT
Line 3462 of GanttComposite:

 toReturn = toReturn.replaceAll(Constants.STR_NAME, ge.getName());

ge.getName()="F0007 Delete $$ files when executing IMPORT [V60LA *CMP]"

throws:

java.lang.IllegalArgumentException: Illegal group reference
	at java.util.regex.Matcher.appendReplacement(Unknown Source)
	at java.util.regex.Matcher.replaceAll(Unknown Source)
	at java.lang.String.replaceAll(Unknown Source)
	at org.eclipse.nebula.widgets.ganttchart.GanttComposite.getStringForEvent(GanttComposite.java:3462)
	at org.eclipse.nebula.widgets.ganttchart.GanttComposite.internalDrawEvents(GanttComposite.java:3158)
	at org.eclipse.nebula.widgets.ganttchart.GanttComposite.drawEvents(GanttComposite.java:3103)
	at org.eclipse.nebula.widgets.ganttchart.GanttComposite.drawChartOntoGC(GanttComposite.java:1122)
	at org.eclipse.nebula.widgets.ganttchart.GanttComposite.repaint(GanttComposite.java:1018)
	at org.eclipse.nebula.widgets.ganttchart.GanttComposite.access$1(GanttComposite.java:1015)
Comment 1 Wim Jongman CLA 2011-07-27 09:39:34 EDT
consider replacing with:

try {
toReturn = toReturn.replaceAll(Constants.STR_NAME, ge.getName());
} catch (IllegalArgumentException e) {
toReturn = toReturn.replaceAll(Constants.STR_NAME, Matcher.quoteReplacement(ge.getName()));
}

replaceAll javadoc:

Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string; see Matcher.replaceAll. Use Matcher.quoteReplacement(java.lang.String) to suppress the special meaning of these characters, if desired.
Comment 2 Wim Jongman CLA 2011-07-27 09:49:26 EDT
(In reply to comment #1)
> consider replacing with:
> 
> try {
> toReturn = toReturn.replaceAll(Constants.STR_NAME, ge.getName());
> } catch (IllegalArgumentException e) {
> toReturn = toReturn.replaceAll(Constants.STR_NAME,
> Matcher.quoteReplacement(ge.getName()));
> }

Yes, that fixed it. The reason I did a try and not always do the quoteReplacement is that I assume that the text normally does not contain these characters and save some precious milliseconds. 

However, there is the case when the text does contain some special texts and the IAE is not thrown. This has to be dealt with when somebody reports this.

do you want me to commit this change?
Comment 3 Makenna Fish CLA 2016-05-25 17:29:29 EDT
Wim, have there been any updates to this issue? I'm currently using a workaround, any chance we can go ahead and apply this fix?
Comment 4 Wim Jongman CLA 2016-05-25 17:37:09 EDT
(In reply to Makenna Fish from comment #3)
> Wim, have there been any updates to this issue? I'm currently using a
> workaround, any chance we can go ahead and apply this fix?

You're on a roll Makenna. Thanks. Please go ahead and put it in.
Comment 5 Makenna Fish CLA 2016-05-25 18:04:42 EDT
No problem, I'm glad I could help!
Comment 6 Eclipse Genie CLA 2016-05-25 18:33:25 EDT
New Gerrit change created: https://git.eclipse.org/r/73675