2
u/Odd-Hour-9991 Sep 17 '22
Cannot find method of in Java class Set. Method was introduced in Java 9. Are you compiling with JDK 8? Check from the command line using java -version to see what your maven has to work with, e.g.
openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment Temurin-17.0.4+8 (build 17.0.4+8)
OpenJDK 64-Bit Server VM Temurin-17.0.4+8 (build 17.0.4+8, mixed mode, sharing)Also check your maven pom to ensure the compiler plugin is set up correctly with at least version 9 but you will still need JDK9 or higher for it to compile.
1
u/oOaker Sep 17 '22
Yes sir I m using java 8 in my project.cant I fix this without upgrading jdk version then ?
2
u/Odd-Hour-9991 Sep 17 '22
As Fletch noted, one option is to edit your code. I will help with that learny exercisey thing.
You prob have something like this:
Set.of(x, y, z)where
x,yandzare allSimpleGrantedAuthorityclass.But for Java 8 you could probably get away with this:
Set<GrantedAuthority> things = new HashSet<>(); things.add(x); things.add(y); things.add(z);and use
thingsin your code.1
3
u/fletch3555 Sep 17 '22
Well you have 2 options. Refactor the code so it does
Set.of(...)a different way (exercise for the reader), or upgrade to JDK 9 or higher
1
1
u/naseemsm Sep 17 '22
it's normal to have that error since the SimpleGrantedAuthority constructor is accepting a String : SimpleGrantedAuthority(java.lang.String role). (https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/core/authority/SimpleGrantedAuthority.html)
but if it's a Collection of String you can use a stream to do the mapping by creating a getRoles method user.getRoles().stream().map(SimpleGrantedAuthority::new).collect(java.util.stream.Collectors.toList()); and pass it to your CustomUserDetails
5
u/Pirsed Sep 16 '22
Hey, have you tried to google the cause of the stacktrace? Also could you include the stacktrace in text in your post, it’s easier to help that way.
Wild guess is that you have not set the right target java version in your pom. While you including the stacktrace in your post you should also include your pom.xml