8000 Fix invalid method reference when compiling with JDK17 by tsaarni · Pull Request #13621 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Fix invalid method reference when compiling with JDK17 - #13621

Merged
mposolda merged 1 commit into
keycloak:mainfrom
Nordix:jdk17-fix-invalid-method-ref
Aug 25, 2022
Merged

mposolda merged 1 commit into
keycloak:mainfrom
Nordix:jdk17-fix-invalid-method-ref

Conversation

@tsaarni
@tsaarni tsaarni commented Aug 8, 2022
Copy link
Copy Markdown
Contributor

This PR fixes compilation error during build of testsuite/model/src/test/java/org/keycloak/testsuite/model/session/ on JDK17 (17.0.4 temurin):

$ mvn clean install -DskipTests  
...
[INFO] Tests for logical storage layer .................... FAILURE [  2.019 s]
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1-jboss-1:testCompile (default-testCompile) on project keycloak-model-test: Compilation failure: Compilation failure: 
[ERROR] /home/tsaarni/work/keycloak-worktree/ldap-starttls-sasl-external-new/testsuite/model/src/test/java/org/keycloak/testsuite/model/session/OfflineSessionPersistenceTest.java:[182,20] incompatible types: invalid method reference
[ERROR]     method getId in interface org.keycloak.models.ClientModel cannot be applied to given types
[ERROR]       required: no arguments
[ERROR]       found:    java.lang.Object
[ERROR]       reason: actual and formal argument lists differ in length
[ERROR] /home/tsaarni/work/keycloak-worktree/ldap-starttls-sasl-external-new/testsuite/model/src/test/java/org/keycloak/testsuite/model/session/OfflineSessionPersistenceTest.java:[240,20] incompatible types: invalid method reference
[ERROR]     method getId in interface org.keycloak.models.ClientModel cannot be applied to given types
[ERROR]       required: no arguments
[ERROR]       found:    java.lang.Object
[ERROR]       reason: actual and formal argument lists differ in length

Updates #8889

@tsaarni
tsaarni commented Aug 8, 2022
Copy link
Copy Markdown
Contributor Author

For reviewers: I'm not sure why compilation error with -> { return <statement> } but not with -> <statement>? That was the difference between similar test cases that compiled vs test cases that failed to compile. Doing this change fixed the compilation error for me.

@mposolda mposolda left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsaarni Looks good, Thanks!

@hmlnarik @ahus1 Anyone of you has a chance to review this small PR? Asking you as it is also a bit related to storage.

@mposolda mposolda self-assigned this Aug 24, 2022
@mposolda
mposolda requested review from ahus1 and hmlnarik August 24, 2022 12:49
@ahus1 ahus1 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look ok, thanks for fixing it. I wish we could have a way to fix the root cause / ensure that it doesn't fail in the future with similar thing. But that's outside of the scope of this.

@tsaarni
tsaarni commented Aug 25, 2022 •
Copy link
Copy Markdown
Contributor Author

I think this would work as well:

@@ -178,8 +178,7 @@ public class OfflineSessionPersistenceTest extends KeycloakModelTest {
         int numClients = 2;
         List<String> clientIds = withRealm(realmId, (session, realm) -> {
             return IntStream.range(0, numClients)
-              .mapToObj(cid -> session.clients().addClient(realm, "client-" + cid))
-              .map(ClientModel::getId)
+              .mapToObj(cid -> session.clients().addClient(realm, "client-" + cid).getId())
               .collect(Collectors.toList());
         });
 
@@ -236,8 +235,7 @@ public class OfflineSessionPersistenceTest extends KeycloakModelTest {
     public void testPersistenceMultipleNodesClientSessionsAtRandomNode() throws InterruptedException {
         List<String> clientIds = withRealm(realmId, (session, realm) -> {
             return IntStream.range(0, 5)
-              .mapToObj(cid -> session.clients().addClient(realm, "client-" + cid))
-              .map(ClientModel::getId)
+              .mapToObj(cid -> session.clients().addClient(realm, "client-" + cid).getId())
               .collect(Collectors.toList());
         });
         List<String> offlineSessionIds = createOfflineSessions(realmId, userIds);

as well as this

@@ -179,7 +179,7 @@ public class OfflineSessionPersistenceTest extends KeycloakModelTest {
         List<String> clientIds = withRealm(realmId, (session, realm) -> {
             return IntStream.range(0, numClients)
               .mapToObj(cid -> session.clients().addClient(realm, "client-" + cid))
-              .map(ClientModel::getId)
+              .map(x -> x.getId())
               .collect(Collectors.toList());
         });
 
@@ -237,7 +237,7 @@ public class OfflineSessionPersistenceTest extends KeycloakModelTest {
         List<String> clientIds = withRealm(realmId, (session, realm) -> {
             return IntStream.range(0, 5)
               .mapToObj(cid -> session.clients().addClient(realm, "client-" + cid))
-              .map(ClientModel::getId)
+              .map(x -> x.getId())
               .collect(Collectors.toList());
         });
         List<String> offlineSessionIds = createOfflineSessions(realmId, userIds);

@mposolda
mposolda merged commit 74b2541 into keycloak:main Aug 25, 2022
@mposolda
Copy link
Copy Markdown
Contributor

@ahus1 Thanks for the additional review. At some point, there is a plan to have testsuite running in the pipeline with JDK 17 (maybe even with GH actions). So at that point, we will be sure that JDK 17 does not break. But AFAIK we're not there yet as you pointed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix invalid method reference when compiling with JDK17

3 participants

0