You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2015/06/04 02:19:38 UTC

[jira] [Comment Edited] (GROOVY-7454) [Static type checking] - Reference to method is ambiguous

    [ https://issues.apache.org/jira/browse/GROOVY-7454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14571882#comment-14571882 ] 

Paul King edited comment on GROOVY-7454 at 6/4/15 12:18 AM:
------------------------------------------------------------

Perhaps you can elaborate on your scenario a little more.

I tried to replicate the issue but the following compiles fine. And a little surprisingly also runs without error.
{code}
@Grab('org.springframework.data:spring-data-mongodb:1.7.0.RELEASE')
import groovy.transform.TypeChecked
import org.springframework.data.repository.Repository
import org.springframework.data.repository.CrudRepository
import org.springframework.data.mongodb.repository.MongoRepository
import org.springframework.data.mongodb.repository.support.SimpleMongoRepository

@TypeChecked
myMethod(Repository r0, CrudRepository r1, MongoRepository r2, SimpleMongoRepository r3) {
  [r0.findAll(), r1.findAll(), r2.findAll(), r3.findAll()]
}

assert myMethod(null, null, null, null) == [[], [], [], []]
{code}
I haven't look into the specifics of the type checker yet but its special handling of findAll for Object and null seems to kick in here even for the marker interface. Using {{@CompileStatic}} causes NPE for all the calls but I presume that isn't what you are concerned about.

If I supply null as the parameter to one of the interface {{findAll}} calls, e.g. {{r2.findAll(null)}} I get NPE errors at runtime from the {{DGM#findAll}} method. This is indicating DGM methods have precedence over interface methods and possibly explains why the static compiler isn't complaining.

If I supply null as the parameter to the class parameter variant, e.g. {{r3.findAll(null)}} I get:
{noformat}
[Static type checking] - Reference to method is ambiguous.
{noformat}
but that is to be expected. If I supply a cast I get a NPE.


was (Author: paulk):
Perhaps you can elaborate on your scenario a little more.

I tried to replicate the issue but the following compiles fine. And a little surprisingly also runs without error.
{code}
@Grab('org.springframework.data:spring-data-mongodb:1.7.0.RELEASE')
import groovy.transform.TypeChecked
import org.springframework.data.repository.Repository
import org.springframework.data.repository.CrudRepository
import org.springframework.data.mongodb.repository.MongoRepository
import org.springframework.data.mongodb.repository.support.SimpleMongoRepository

@TypeChecked
myMethod(Repository r0, CrudRepository r1, MongoRepository r2, SimpleMongoRepository r3) {
  [r0.findAll(), r1.findAll(), r2.findAll(), r3.findAll()]
}

assert myMethod(null, null, null, null) == [[], [], [], []]
{code}
I haven't look into the specifics of the type checker yet but its special handling of findAll for Object and null seems to kick in here even for the marker interface. Using {{@CompileStatic}} causes NPE for all the calls but I presume that isn't what you are concerned about.

If I supply null as the parameter to one of the interface {{findAll}} calls, e.g. {{r2.findAll(null)}} I get NPE errors at runtime from the {{DGM#findAll}} method. This is indicating DGM methods have precedence over interface methods and possibly explains why the static compiler isn't complaining.

If I suppler null as the parameter to the class, e.g. {{r3.findAll(null)}} I get:
{noformat}
[Static type checking] - Reference to method is ambiguous.
{noformat}
but that is to be expected. If I supply a cast I get a NPE.

> [Static type checking] - Reference to method is ambiguous
> ---------------------------------------------------------
>
>                 Key: GROOVY-7454
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7454
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.4.3
>            Reporter: Christopher Smith
>            Assignee: Cédric Champeau
>
> This issue has a number of seeming duplicates marked as "fixed", but I'm reliably seeing it in 2.4.3 when calling `findAll()` on any Spring `CrudRepository`:
> {code}
> Groovy:[Static type checking] - Reference to method is ambiguous. Cannot choose between [java.util.List <T> org.springframework.data.mongodb.repository.MongoRepository#findAll(), java.util.List <T> org.springframework.data.mongodb.repository.MongoRepository#findAll()]
> {code}
> No idea whether this is triggered in particular by the name of the method, which Groovy defines on {{Object}}.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)