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

Bug 346935

Summary: [Scanner Discovery] PatternSyntaxException from build output parser
Product: [Tools] CDT Reporter: Anton Leherbauer <aleherb+eclipse>
Component: cdt-buildAssignee: Anton Leherbauer <aleherb+eclipse>
Status: RESOLVED FIXED QA Contact: Andrew Gvozdev <angvoz.dev>
Severity: normal    
Priority: P3 CC: cdtdoug
Version: 7.0.2Flags: angvoz.dev: review+
Target Milestone: 8.0   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:
Attachments:
Description Flags
Committed fix aleherb+eclipse: iplog-

Description Anton Leherbauer CLA 2011-05-24 02:59:25 EDT
java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
*
^
at java.util.regex.Pattern.error(Pattern.java:1713)
at java.util.regex.Pattern.sequence(Pattern.java:1878)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.compile(Pattern.java:1460)
at java.util.regex.Pattern.<init>(Pattern.java:1133)
at java.util.regex.Pattern.compile(Pattern.java:823)
at java.lang.String.replaceFirst(String.java:2146)
at org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCPerFileBOPConsoleParser.processCommand(GCCPerFileBOPConsoleParser.java:118)
at org.eclipse.cdt.make.internal.core.scannerconfig.gnu.AbstractGCCBOPConsoleParser.processSingleLine(AbstractGCCBOPConsoleParser.java:300)
at org.eclipse.cdt.make.internal.core.scannerconfig.gnu.AbstractGCCBOPConsoleParser.processLine(AbstractGCCBOPConsoleParser.java:141)
Comment 1 Andrew Gvozdev CLA 2011-05-24 12:05:33 EDT
The exception is pointing to the line
tokens[i]= token.replaceFirst(shortFileName, "SHORT_NAME"); //$NON-NLS-1$

Can you look in your build output for the line that could possibly cause the error? A line with an asterisk '*' that the parser could interpret as a file name.
Comment 2 Anton Leherbauer CLA 2011-05-25 02:20:41 EDT
(In reply to comment #1)
> The exception is pointing to the line
> tokens[i]= token.replaceFirst(shortFileName, "SHORT_NAME"); //$NON-NLS-1$
> 
> Can you look in your build output for the line that could possibly cause the
> error? A line with an asterisk '*' that the parser could interpret as a file
> name.

Yes, I know.  However, there should be no PatternSyntaxException.  A simple Pattern.quote(shortFileName) should do.
Comment 3 Andrew Gvozdev CLA 2011-05-25 06:43:49 EDT
(In reply to comment #2)
> > Can you look in your build output for the line that could possibly cause the
> > error? A line with an asterisk '*' that the parser could interpret as a file
> > name.
> Yes, I know.  However, there should be no PatternSyntaxException.  A simple
> Pattern.quote(shortFileName) should do.
I agree, but could you indulge my curiosity?
Comment 4 Anton Leherbauer CLA 2011-05-25 07:23:09 EDT
(In reply to comment #3)
> > Yes, I know.  However, there should be no PatternSyntaxException.  A simple
> > Pattern.quote(shortFileName) should do.
> I agree, but could you indulge my curiosity?

Sorry, I no longer have the build output at hand.
Comment 5 Anton Leherbauer CLA 2011-05-27 06:18:39 EDT
Created attachment 196742 [details]
Committed fix

I committed a slightly different fix which avoids the use of a regex pattern altogether, which should also be a little better in terms of performance.
Comment 6 Anton Leherbauer CLA 2011-05-27 06:19:40 EDT
Andrew, please review my fix.
Comment 7 CDT Genie CLA 2011-05-27 06:23:09 EDT
*** cdt cvs genie on behalf of aleherbau ***
Bug 346935 - [Scanner Discovery] PatternSyntaxException from build output parser

[*] GCCPerFileBOPConsoleParser.java 1.29 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParser.java?root=Tools_Project&r1=1.28&r2=1.29
Comment 8 Andrew Gvozdev CLA 2011-05-27 14:20:52 EDT
(In reply to comment #6)
> Andrew, please review my fix.
The fix certainly gets rid of the exception, although after looking a bit more closely I don't think it is the right solution. The purpose of the parser is to collect settings for the file being compiled, if the name contains star the parser has already failed to identify the file. I think the better solution is to quit processing the line as soon as we discovered that the file name is invalid or even better adjust parsing algorithm to reject the line way earlier. That is why I was interested to see the line from output, chances are that parsing went south way before that line of code.
But I am unwilling to do any changes to parsing that close to the release and think your patch makes no harm, hence the '+'.

Last question, does the exception prevent parser from parsing the rest of output? That would be really bad.
Comment 9 Anton Leherbauer CLA 2011-05-30 03:48:38 EDT
(In reply to comment #8)
> (In reply to comment #6)
> > Andrew, please review my fix.
> The fix certainly gets rid of the exception, although after looking a bit more
> closely I don't think it is the right solution.

It does exactly the same as before, just without throwing an exception ;-)
I am not trying to improve the heuristics of the build output parser.

> Last question, does the exception prevent parser from parsing the rest of
> output? That would be really bad.

Yes, I think so.  Looking at the stacktrace and code it seems the exception is not caught anywhere and thus makes an end to build output parsing.