jonahgraham / protobuf-dt

Automatically exported from code.google.com/p/protobuf-dt
0 stars 0 forks source link

Path separator usage in regex pattern on windows causes uncaught exception during build #119

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Try to build a project on a Windows platform
2.
3.

What is the expected output? What do you see instead?
Expected to compile without errors.

An exception is thrown by protobuf-dt and caught by Eclipse...

java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
 ^
    at java.util.regex.Pattern.error(Pattern.java:1713)
    at java.util.regex.Pattern.compile(Pattern.java:1466)
    at java.util.regex.Pattern.<init>(Pattern.java:1133)
    at java.util.regex.Pattern.compile(Pattern.java:823)
    at java.lang.String.split(String.java:2292)
    at java.lang.String.split(String.java:2334)
    at com.google.eclipse.protobuf.ui.builder.OutputDirectories.findOrCreateOutputDirectory(OutputDirectories.java:45)
    at com.google.eclipse.protobuf.ui.builder.OutputDirectories.findOrCreateOutputDirectory(OutputDirectories.java:41)
    at com.google.eclipse.protobuf.ui.builder.OutputDirectories.findOrCreateOutputDirectories(OutputDirectories.java:34)
    at com.google.eclipse.protobuf.ui.builder.ProtobufBuildParticipant.build(ProtobufBuildParticipant.java:52)
    at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
    at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:160)
    at org.eclipse.xtext.builder.impl.XtextBuilder.fullBuild(XtextBuilder.java:182)
    at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:85)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

What version of the product are you using? On what operating system?
1.0.2 Windows 7 x64
(issue should affect all operating systems that use the "\" character as the 
path separator.

Please provide any additional information below.
The Regex pattern fails to compile because the "\" character is an escape 
sequence in java Regex.

The code in question is in 
com.google.eclipse.protobuf.ui.builder.OutputDirectories
in function findOrCreateOutputDirectory
on line 45
    String[] segments = outputFolderName.split(separator);
and can be corrected by the change
    String[] segments = outputFolderName.split("\\Q"+separator+"\\E");

Where the escape sequence "\Q ... \E" in java Regex will escape all characters 
contained within the sequence.

Original issue reported on code.google.com by compuwar...@gmail.com on 14 Sep 2011 at 7:26

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by alr...@google.com on 15 Sep 2011 at 6:25

GoogleCodeExporter commented 9 years ago
Thanks so much for reporting this issue, and for providing a fix!

I also found some code duplication (check rbc2aec2d70cb)

Original comment by alr...@google.com on 15 Sep 2011 at 6:36

GoogleCodeExporter commented 9 years ago
Issue 130 has been merged into this issue.

Original comment by alr...@google.com on 10 Oct 2011 at 6:17