question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I got (Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 6)

See original GitHub issue

I’m new to karate and cucumber. I wrote below test:

Feature: ثبت نام کاربر با ایمیل تکراری

  Scenario: در صورتی‌که ایمیل، تکراری باشد، باید کد وضعیت ۴۰۰، وضعیت پارامترهای اشتباه، خطای ورودی ایمیل تکراری را بدهد


    Given url karate.get('urlBase') +  "user/registerUser"
    And request
"""
  {
    "username" :#(karate.get('defaultUsername')),
    "mobile":#(karate.get('defaultMobile')),
    "email":#(karate.get('defaultEmail')),
    "nationalCode":#(karate.get('defaultNationalID')),
    "firstName":#(karate.get('defaultFirstName')),
    "middleName":#(karate.get('defaultMiddleName')),
    "lastname":#(karate.get('defaultLastName')),
    "password":#(karate.get('defaultPassword'))
  }
"""
    When method post
    Then status 200
    And match response ==
  """
  {
   "status":0,
   "message":#(karate.get('status0persianMessage'))
  }
"""

    Given url karate.get('urlBase') +  "user/registerUser"
    And request
"""
  {
    "username":#(karate.get('defaultUsername')),
    "mobile":#(karate.get('defaultMobile')),
    "email":#(karate.get('defaultEmail')),
    "nationalCode":#(karate.get('defaultNationalID')),
    "firstName":#(karate.get('defaultFirstName')),
    "middleName":#(karate.get('defaultMiddleName')),
    "lastname":#(karate.get('defaultLastName')),
    "password":#(karate.get('defaultPassword'))
  }
"""
    When method post

    Then status 200
    And match response ==
    """
    {
    	"status": 0
    }
    """

but I got below error:

`“C:\Program Files (x86)\Java\jdk1.8.0_112\bin\java” “-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.2\lib\coverage-agent.jar=C:\Users\Homayoun\AppData\Local\Temp\coverage21839args” -Dorg.jetbrains.run.directory=C:\Users\Homayoun\Documents\Projects\HamrahDoctor\HamrahDoctorApiTest\api\src\res “-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.2\lib\idea_rt.jar=63829:C:\Program Files\JetBrains\IntelliJ IDEA 2017.2\bin” -Dfile.encoding=UTF-8 -classpath “C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\charsets.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\deploy.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\access-bridge-32.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\cldrdata.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\dnsns.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\jaccess.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\jfxrt.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\localedata.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\nashorn.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\sunec.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\sunjce_provider.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\sunmscapi.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\sunpkcs11.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\ext\zipfs.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\javaws.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\jce.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\jfr.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\jfxswt.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\jsse.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\management-agent.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\plugin.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\resources.jar;C:\Program Files (x86)\Java\jdk1.8.0_112\jre\lib\rt.jar;C:\Users\Homayoun\Documents\Projects\HamrahDoctor\HamrahDoctorApiTest\api\target\test-classes;C:\Users\Homayoun\Documents\Projects\HamrahDoctor\HamrahDoctorApiTest\api\target\classes;C:\Users\Homayoun.m2\repository\com\intuit\karate\karate-junit4\0.6.0.9\karate-junit4-0.6.0.9.jar;C:\Users\Homayoun.m2\repository\com\intuit\karate\karate-core\0.6.0.9\karate-core-0.6.0.9.jar;C:\Users\Homayoun.m2\repository\com\jayway\jsonpath\json-path\2.1.0\json-path-2.1.0.jar;C:\Users\Homayoun.m2\repository\net\minidev\json-smart\2.2\json-smart-2.2.jar;C:\Users\Homayoun.m2\repository\net\minidev\accessors-smart\1.1\accessors-smart-1.1.jar;C:\Users\Homayoun.m2\repository\org\ow2\asm\asm\5.0.3\asm-5.0.3.jar;C:\Users\Homayoun.m2\repository\info\cukes\cucumber-java\1.2.5\cucumber-java-1.2.5.jar;C:\Users\Homayoun.m2\repository\org\yaml\snakeyaml\1.18\snakeyaml-1.18.jar;C:\Users\Homayoun.m2\repository\info\cukes\cucumber-junit\1.2.5\cucumber-junit-1.2.5.jar;C:\Users\Homayoun.m2\repository\info\cukes\cucumber-core\1.2.5\cucumber-core-1.2.5.jar;C:\Users\Homayoun.m2\repository\info\cukes\cucumber-html\0.2.3\cucumber-html-0.2.3.jar;C:\Users\Homayoun.m2\repository\info\cukes\cucumber-jvm-deps\1.0.5\cucumber-jvm-deps-1.0.5.jar;C:\Users\Homayoun.m2\repository\info\cukes\gherkin\2.12.2\gherkin-2.12.2.jar;C:\Users\Homayoun.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\Homayoun.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\Homayoun.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\Homayoun.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\Homayoun.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\Homayoun.m2\repository\com\intuit\karate\karate-apache\0.6.0\karate-apache-0.6.0.jar;C:\Users\Homayoun.m2\repository\org\apache\httpcomponents\httpclient\4.5.3\httpclient-4.5.3.jar;C:\Users\Homayoun.m2\repository\org\apache\httpcomponents\httpcore\4.4.6\httpcore-4.4.6.jar;C:\Users\Homayoun.m2\repository\commons-codec\commons-codec\1.9\commons-codec-1.9.jar;C:\Users\Homayoun.m2\repository\org\apache\httpcomponents\httpmime\4.5.3\httpmime-4.5.3.jar;C:\Users\Homayoun.m2\repository\org\slf4j\jcl-over-slf4j\1.7.25\jcl-over-slf4j-1.7.25.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2017.2\plugins\cucumber-java\lib\cucumber-jvm-formatter.jar” cucumber.api.cli.Main --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvmSMFormatter --monochrome --name “^در صورتی\‌که ایمیل\، تکراری باشد\، باید کد وضعیت ۴۰۰\، وضعیت پارامترهای اشتباه\، خطای ورودی ایمیل تکراری را بدهد$” --glue com.intuit.karate C:/Users/Homayoun/Documents/Projects/HamrahDoctor/HamrahDoctorApiTest/api/src/res/register.user.post.duplicate.email.feature Testing started at 9:04 AM … ---- IntelliJ IDEA coverage runner ---- sampling … include patterns: cucumber.api.cli..* exclude patterns: Exception in thread “main” java.util.regex.PatternSyntaxException: Dangling meta character ‘?’ near index 6 ^?? ?????? ???? ??? ???? ??? ?? ??? ???? ??? ??? ???? ??? ??? ??? ??? ?? ???$ ^ at java.util.regex.Pattern.error(Pattern.java:1955) at java.util.regex.Pattern.sequence(Pattern.java:2123) at java.util.regex.Pattern.expr(Pattern.java:1996) at java.util.regex.Pattern.compile(Pattern.java:1696) at java.util.regex.Pattern.<init>(Pattern.java:1351) at java.util.regex.Pattern.compile(Pattern.java:1028) at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:140) at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:85) at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:78) at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:70) at cucumber.api.cli.Main.run(Main.java:31) at cucumber.api.cli.Main.main(Main.java:18)

Process finished with exit code 1 `

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ptrthomascommented, Oct 10, 2017

ok thanks for the update. glad to know things are working. ignore the file.encoding, it is not needed for you.

yes people tell me the documentation is too much 😃 but there is an interesting advantage, you can do CTRL F and find anything you want very easily !

1reaction
ptrthomascommented, Oct 10, 2017

hey I read the stack trace more carefully - this is what is causing the problem:

cucumber.api.cli.Main --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvmSMFormatter --monochrome --name "^در صورتی\‌که ایمیل\، تکراری باشد\، باید کد وضعیت ۴۰۰\، وضعیت پارامترهای اشتباه\، خطای ورودی ایمیل تکراری را بدهد$" --glue com.intuit.karate 

try this:

  • in IntelliJ - run the whole feature, not the selected scenario
  • or change the name of the scenario to english (which you may not want)
  • or use a JUnit runner with the RunWith(Karate.class) annotation like mentioned in the documentation: https://github.com/intuit/karate#running-with-junit

I’m closing this - because this is not an issue with Karate, it is the combination of Cucumber, your environment and IntelliJ

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tokenizing Error: java.util.regex.PatternSyntaxException ...
No, the problem is that * is a reserved character in regexes, so you need to escape it. String [] separado = line.split("\\*");....
Read more >
java.util.regex.PatternSyntaxException ... - Yawin Tutor
The java exception java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0 happens when the string is matched by the regular ...
Read more >
dangling meta character '+' near index 0 - Java Hungry
In this post, I will be sharing how to solve java.util.regex.PatternSyntaxException in Java. PatternSyntaxException is an Unchecked exception.
Read more >
I got (Exception in thread "main" java.util.regex ... - GitHub
I got (Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 6) #212.
Read more >
How to solve: Dangling meta character '?' near index 0
The first argument in replaceAll() takes a regular expression. The character '?' has a special meaning in regular expressions. So you have ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found