Exception when using method reference in lamba "Class<?>[]::new" #2729

Closed
valliman opened this Issue Dec 17, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@valliman

Using Checkstyle version 6.13

When using the method reference "Class<?>[]::new" in a lambda expression like:

//Compilable with Java8
//Issue #2729
package com.puppycrawl.tools.checkstyle.grammars.java8;
import java.util.Arrays;

public class InputMethodReferences4 {
    public void doSomething(final Object... arguments) {
        Arrays.stream(arguments)
                .map(Object::getClass)
                .toArray(Class<?>[]::new);
    }
}

the exception below is thrown:

Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing SomeClass.java
    at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:282)
    at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:252)
    at org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo.execute(CheckstyleViolationCheckMojo.java:538)
    ... 27 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: MismatchedTokenException occurred during the analysis of file SomeClass.java
    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:218)
    at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:79)
    at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:266)
    ... 29 more
Caused by: SomeClass.java:37:13: expecting EOF, found 'Method'
    at antlr.Parser.match(Parser.java:211)
    at com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaRecognizer.compilationUnit(GeneratedJavaRecognizer.java:210)
    at com.puppycrawl.tools.checkstyle.TreeWalker.parse(TreeWalker.java:468)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:200)
    ... 31 more

Using instead "size -> new Class<?>[size]" is a workaround.

@sabaka

This comment has been minimized.

Show comment
Hide comment
@sabaka

sabaka Dec 24, 2015

Contributor

I use this file in tests now.
Problem is Class<?>[]::new
Our grammar doesn't know, that here can be an array.
I think I can fix it by simply adding [] to this rule, but better to put an existed rule here with all possible cases, because we want to understand our grammar in future :)

Contributor

sabaka commented Dec 24, 2015

I use this file in tests now.
Problem is Class<?>[]::new
Our grammar doesn't know, that here can be an array.
I think I can fix it by simply adding [] to this rule, but better to put an existed rule here with all possible cases, because we want to understand our grammar in future :)

sabaka added a commit to sabaka/checkstyle that referenced this issue Dec 30, 2015

sabaka added a commit to sabaka/checkstyle that referenced this issue Dec 31, 2015

sabaka added a commit to sabaka/checkstyle that referenced this issue Dec 31, 2015

sabaka added a commit to sabaka/checkstyle that referenced this issue Dec 31, 2015

sabaka added a commit to sabaka/checkstyle that referenced this issue Jan 5, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Jan 5, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Jan 5, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Jan 5, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Jan 7, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Jan 7, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Jan 7, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Jan 10, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Feb 9, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Feb 9, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Feb 9, 2016

romani added a commit that referenced this issue Feb 10, 2016

@romani romani added the bug label Feb 10, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Mar 7, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Mar 7, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Mar 7, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Mar 7, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Mar 8, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Mar 8, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Mar 8, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Mar 8, 2016

sabaka added a commit to sabaka/checkstyle that referenced this issue Mar 9, 2016

romani added a commit that referenced this issue Mar 9, 2016

@romani romani added this to the 6.17 milestone Mar 9, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Mar 9, 2016

Member

fix is merged.

Member

romani commented Mar 9, 2016

fix is merged.

@romani romani closed this Mar 9, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment