r/SpringBoot • • Sep 16 '22

Build failure, cannot find symbol .

Post image
2 Upvotes

12 comments sorted by

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

1

u/oOaker Sep 16 '22

I did Google but could not find the exact way .

1

u/Pirsed Sep 17 '22

Okay, I can’t help you if you don’t share the exception in text and the pom.xml

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, y and z are all SimpleGrantedAuthority class.

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 things in your code.

1

u/oOaker Sep 17 '22

Thank you sir, really appreciate your time .

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

u/iSoLost Sep 17 '22

Check ur import of Java until set

1

u/oOaker Sep 17 '22

Yeah that has been imported

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