SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


Bug JT_Category_Number

Inspired by

Original Description

The code here uses a regular expression that is invalid according to the syntax for regular expressions. This statement will throw a PatternSyntaxException when executed. – 2013-10-14

Detailed Description

Syntax errors also called as parsing errors, are caught by ParseSyntaxException in Java whenever incorrect syntax is passed in any regular expression.

Sample Problem Scenario

<code Java> public class PatternExample {

public static void main(String[] args) {
	Pattern pattern = Pattern.compile('.xx.');
	Matcher matcher = pattern.matcher('MxxY');
	System.out.println('Input String matches regex - '+matcher.matches());
	// bad regular expression
	pattern = Pattern.compile('*xx*');
}

} </Code>

Sample Fix

<code Java> String str = 'bbb'; System.out.println('Using String matches method: '+str.matches('.bb')); System.out.println('Using Pattern matches method: '+Pattern.matches('.bb', str)); </Code>

Evaluation Results

Benchmark project Precision Recall
FB JT Delta FB JT Delta
Project … …% …% …% …% …% …%
Project … …% …% …% …% …% …%

FB = FindBugs, JT = JTransformer, Delta = JTransformer - FindBugs

teaching/labs/mdse/2013/bug_descriptions/jt-bug-cor103.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2024