[ https://issues.apache.org/jira/browse/RATIS-703?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16946500#comment-16946500 ]
Henrik Hegardt edited comment on RATIS-703 at 10/8/19 8:02 AM: --------------------------------------------------------------- Yes, CheckedSupplier and CheckedRunnable are two different classes but when they are written as expressions it's ambiguous if they should return a value or not since the syntax is the same for both. Everywhere it looks like this: {code:java} JavaUtils.attempt(() -> assertNotLeaderException(newLeader, "m2", oldLeader, rpc, cluster), 10, ONE_SECOND, "assertNotLeaderException", LOG); {code} the compiler cannot decide if it should use the returning CheckedSupplier or the non-returning one in CheckedRunnable since there's not enough information for it to uniquely decide which class that fit the scenario, thus it's ambiguous. The following line can be resolved by the compiler because it has a return value and thus fits the CheckedSupplier's signature. {code:java} int value = JavaUtils.attempt(() -> assertNotLeaderException(newLeader, "m2", oldLeader, rpc, cluster), 10, ONE_SECOND, "assertNotLeaderException", LOG); {code} So it's not really the JavaUtils.attempt which is ambiguous, but that there are two options for the compiler which fit the method's signature. I don't know why this isn't failing every time though as it should, IMO. For the record, I'm using: {code:java} java version "1.8.0_171" Java(TM) SE Runtime Environment (build 1.8.0_171-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode) {code} was (Author: hheg): Yes, CheckedSupplier and CheckedRunnable are two different classes but when they are written as expressions it's ambiguous if they should return a value or not since the syntax is the same for both. Everywhere it looks like this: {code:java} JavaUtils.attempt(() -> assertNotLeaderException(newLeader, "m2", oldLeader, rpc, cluster), 10, ONE_SECOND, "assertNotLeaderException", LOG); {code} the compiler cannot decide if it should use the returning CheckedSupplier or the non-returning one in CheckedRunnable since there's not enough information for it to uniquely decide which class that fit the scenario, thus it's ambiguous. The following line can be resolved by the compiler because it has a return value and thus fits the CheckedSupplier's signature. {code:java} int value = JavaUtils.attempt(() -> assertNotLeaderException(newLeader, "m2", oldLeader, rpc, cluster), 10, ONE_SECOND, "assertNotLeaderException", LOG); {code} So it's not really the JavaUtils.attempt which is ambiguous, but that there are two options for the compiler which fit the method's signature. I don't know why this is failing every time though as it should, IMO. For the record, I'm using: {code:java} java version "1.8.0_171" Java(TM) SE Runtime Environment (build 1.8.0_171-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode) {code} > Intermittent ambiguous method reference > --------------------------------------- > > Key: RATIS-703 > URL: https://issues.apache.org/jira/browse/RATIS-703 > Project: Ratis > Issue Type: Bug > Reporter: Henrik Hegardt > Assignee: Henrik Hegardt > Priority: Major > Attachments: RATIS-703.00.patch > > > I'm getting intermittent ambiguous method reference compilation errors. It > seems like it's a real bug since the method is ambigious when the referenced > generic types have been ereased. Though I'm not sure why this is not always > failing, it should, but it's probably a bug in Javac. I'm running Eclipse and > it consistently complains about it. > Output from Maven: > [ERROR] > testRevertConfigurationChange(org.apache.ratis.server.simulation.TestRaftReconfigurationWithSimulatedRpc) > Time elapsed: 0.108 s <<< ERROR! > java.lang.Error: > Unresolved compilation problems: > The method attempt(CheckedSupplier<Boolean,RuntimeException>, int, > TimeDuration, String, Logger) is ambiguous for the type JavaUtils > The method attempt(CheckedSupplier<Boolean,RuntimeException>, int, > TimeDuration, String, Logger) is ambiguous for the type JavaUtils > [INFO] Running > org.apache.ratis.server.simulation.TestServerRestartWithSimulatedRpc > [ERROR] Tests run: 5, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: > 4.013 s <<< FAILURE! - in > org.apache.ratis.server.simulation.TestServerRestartWithSimulatedRpc > [ERROR] > testRestartCommitIndex(org.apache.ratis.server.simulation.TestServerRestartWithSimulatedRpc) > Time elapsed: 0.081 s <<< ERROR! > java.lang.Error: > Unresolved compilation problems: > The method attempt(CheckedSupplier<Boolean,RuntimeException>, int, > TimeDuration, String, Logger) is ambiguous for the type JavaUtils > The method attempt(CheckedSupplier<Boolean,RuntimeException>, int, > TimeDuration, String, Logger) is ambiguous for the type JavaUtils > [ERROR] > testRestartFollower(org.apache.ratis.server.simulation.TestServerRestartWithSimulatedRpc) > Time elapsed: 0.074 s <<< ERROR! > java.lang.Error: > Unresolved compilation problem: > The method attempt(CheckedSupplier<Boolean,RuntimeException>, int, > TimeDuration, String, Logger) is ambiguous for the type JavaUtils > A fix (but ugly) would just to be to re arrange the arguments. > -- This message was sent by Atlassian Jira (v8.3.4#803005)