Description
With the following code:
public interface APSBusRouter { boolean send( @NotNull String target, @NotNull Map<String, Object> message, @Optional @Nullable APSHandler<APSResult<?>> resultHandler ); }
void send( @NotNull String target, @NotNull Map<String, Object> message, @Optional @Nullable APSHandler<APSResult<?>> resultHandler ) { if ( validateBaseMessageStructure( message ) ) { boolean valid = false this.routerTracker.withAllAvailableServices() { APSBusRouter apsBusRouter, @NotUsed Object[] args -> ---> if ( apsBusRouter.send( target.trim(), message, resultHandler ) ) { valid = true } } ...
There will be a compilation error:
Error:(236, 22) Groovyc: [Static type checking] - Cannot call se.natusoft.osgi.aps.api.messaging.APSBusRouter#send(java.lang.String, java.util.Map <java.lang.String, java.lang.Object>, se.natusoft.osgi.aps.types.APSHandler <se.natusoft.osgi.aps.types.APSResult>) with arguments [java.lang.String, java.util.Map <String, Object>, se.natusoft.osgi.aps.types.APSHandler <APSResult>]
This because the resultHandler in the interface APSBusRouter for send method is declared identical to the argument of same name in method, and this argument is just passed on. Here the Groovy compiler cannot find the send method called.
But if the APSBusRouter interface is changed and the <?> part after APSResult is removed (making IDEA complain and correctly so !!) then this compiles perfectly! This even though the passed resultHandler in this case is not identical to the APSBusRouter.send(...) declaration of the resultHandler argument.
Example on github:
APSBusRouter.java: https://github.com/tombensve/APS/blob/4a0e5d56d61d218e55c1eb3b5edec1c6d44a40ba/APS-APIs/src/main/java/se/natusoft/osgi/aps/api/messaging/APSBusRouter.java#L106
APSBusProvider.groovy: https://github.com/tombensve/APS/blob/4a0e5d56d61d218e55c1eb3b5edec1c6d44a40ba/APS-Libraries/APSCoreLib/src/main/groovy/se/natusoft/osgi/aps/core/service/APSBusProvider.groovy#L227
Both of these links are on Branch "Groovy-3_0_1-Issue". Ignore the annotations in methods, they are purely for documentation purpose, and yes there is clearly a bug in this method , but it has nothing to do with this issue.
The workaround for this is to remove the <?> part in APSBusRouter.send(...) method declaration.
Personally I'm starting to think that maybe it is the "<?>" expression Groovy has a problem with. The interface is in this case done in Java! But then again in APSBusProvider.groovy it does allow this in the send(...) method declaration. Maybe Groovy sees <?> differently than Java ? That is, Groovy code accepts this, but it does not mean the same thing as in Java ?
Attachments
Issue Links
- relates to
-
GROOVY-10525 Regression in 2.5.16: Class<?>[] cannot be assigned to Class<?>...
- Closed