0

I am trying to build (in Eclipse) and use the code in this older thread:

How do I pass the client certificate with HTTP client?

But I am having problems compiling it because this line is causing the compiler to flag an error:

        SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(
            MutualHttpsMain.class.getResource(TEST_CLIENT_KEYSTORE_RESOURCE),
            storePassword, keyPassword,
            (aliases, socket) -> aliases.keySet().iterator().next()
    ).build();

The error is:

error: lambda expressions are not supported in -source 1.7

My understanding is that lambda expressions were not supported in Java/JDK 1.7, so it seems like Eclipse (or Maven) thinks that the compiler is 1.8, but I've gone through my Eclipse configuration and everything appears to be configured for using JDK 1.8, so I don't know why I am still getting the error, so I am wondering: Is it possible to convert that line so it is no longer a lambda expression?

Can someone here help with that?

EDIT: Sorry, I had to correct the text of the error above... the correct error message say "1.7" and not "7" :( !!

user555303
  • 1,146
  • 3
  • 20
  • 44
  • 2
    It is possible, but I'd advise you to look for the "-source 7" issue. I'd guess it's in a maven file ("7"). – daniu Aug 31 '23 at 10:35
  • 1
    just to clarify, do you really want to compile with java 1.7 (basically backport your code to java 1.7) and looking for non-lambda alternative of the code snippet or the issue is that eclipse doesn't compile with 1.8 for some reason? If you want to remove lambda (and sure that there are no other java 8 code parts in your codebase) then please check the definition of `loadKeyMaterial` method. Its last parameter must be an interface, please post it in the question as well so that we could provide a working non-lambda alternative – Mark Bramnik Aug 31 '23 at 10:46
  • Look at the Javadoc for `loadKeyMaterial`, see what type it expects for that parameter, and create an instance of that type, presumably by creating an anonymous instance. But as others have said, check your pom.xml – tgdavies Aug 31 '23 at 10:54
  • @MarkBramnik - I am not wanting to compile with java 1.7... I was asking this question because I have spent a lot time trying to (unsuccessfully) figure out why Eclipse/Maven thinks it should be building using Java 1.7 already, so I thought that an alternative might be just getting rid of the lambda expression from the code. Not optimal, I know, but just really frustrated. Sorry – user555303 Aug 31 '23 at 11:29
  • @daniu - when you say "a maven file", which file or files were you referring to? Thanks! – user555303 Aug 31 '23 at 11:30
  • @daniu - I just editd the original post to correct the error message - it says "1.7", not "7". I think I actually saw that somewhere last night in one of the files (I think it was 'source' and 'target') and I tried changing that to 1.8, but it didn't work. I'll try to find it again now ... – user555303 Aug 31 '23 at 11:36
  • @daniu - I found the 1.7 references again. It is in the src-parent/pom.xml and has "source" and "target" set to "1.7". I know I tried changing this last night but I'll do it again and try a build again now and will post back. – user555303 Aug 31 '23 at 11:40
  • 1
    @daniu - I made the change in the file and now it compiled! Like I said I remember finding and trying a build last night, but I think I may've mistakenly built the wrong project last night :( !! – user555303 Aug 31 '23 at 12:00
  • 1
    I see, so try to make two things: 1. Post maven pom.xml - what happens when you compile outside eclipse (mvn clean package) - does it compile? Especially check the properties and the definitions of maven compiler plugin in your pom.xml (you might also have defaults, which is java 1.5 at all) 2. Post the interface like I've asked in the previous comment - this is required to help you to create a non-lambda alternative for this specific case. – Mark Bramnik Aug 31 '23 at 12:01
  • @all - so I think, as far as the original question about the build problem, I am good now. Thanks for ALL of the help/questions!! I think that I've been to deep/heads-down on this thing so they were all helpful. Thanks again!!! – user555303 Aug 31 '23 at 12:02
  • @daniu - I think I know what I did wrong last night - so last night, I found the 1.7 values in the src-parent/pom.xml, and I made the change in that pom.xml, then I tried to do the Run As->Maven build on the src-parent, and THAT build failed (and also failed just before now. But then after it failed just before now, I decided to do the Run As on the actual project I was working on, which was the one I was getting the lambda error on, and when I tried to build THAT project after changing the src-parent/pom.xml, the specific project built all right !! – user555303 Aug 31 '23 at 12:07
  • The problem is not limited to the posted code but also in the code that expects a lambda as an argument to a method. The entire structure may be completely different. – WJS Aug 31 '23 at 12:55

0 Answers0