#1429 Java - Parse Error: Cast in return expression

This commit is contained in:
Andreas Dangel
2015-10-10 16:08:38 +02:00
parent 6b60b4be34
commit a7a84766bd
4 changed files with 32 additions and 0 deletions

View File

@ -1,4 +1,9 @@
/**
* Fix for Cast Expression not detected properly in Return statements
* Bug #1429
*
* Andreas Dangel 10/2015
*====================================================================
* Fix for Lambda expressions without variables.
*
* Andreas Dangel 11/2014
@ -1725,6 +1730,7 @@ void UnaryExpressionNotPlusMinus() #UnaryExpressionNotPlusMinus((jjtn000.getImag
{
( "~" {jjtThis.setImage("~");} | "!" {jjtThis.setImage("!");} ) UnaryExpression()
| LOOKAHEAD( CastExpression() ) CastExpression()
| LOOKAHEAD("(" Type() ")" "(") CastExpression()
| PostfixExpression()
}

View File

@ -108,6 +108,12 @@ public class ParserCornersTest extends ParserTst {
}
}
@Test
public void testBug1429ParseError() throws Exception {
String c = IOUtils.toString(this.getClass().getResourceAsStream("Bug1429.java"));
parseJava18(c);
}
private String readAsString(String resource) {
InputStream in = ParserCornersTest.class.getResourceAsStream(resource);
try {

View File

@ -0,0 +1,18 @@
public class Bug1429 {
public Set<String> getAttributeTuples() {
return (Set<String>) (this.attributes == null ? Collections.<String> emptySet() : new HashSet<String>(
CollectionUtils.collect(this.attributes.keySet(), new Transformer() {
@Override
public Object transform(final Object obj) {
final String key = (String) obj;
final String value = HGXLIFFTypeConfiguration.this.attributes.get(key);
String result = key;
if (StringUtils.isNotEmpty(value)) {
result = result.concat(":").concat(value);
}
return result;
}
})));
}
}

View File

@ -12,4 +12,6 @@
**Bugfixes:**
* [#1429](https://sourceforge.net/p/pmd/bugs/1429/): Java - Parse Error: Cast in return expression
**API Changes:**