0

When importing maven dependencies for GraphQL, got a error (The type java.util.Optional cannot be resolved. It is indirectly referenced from required .class files). I have a class in my project which is extending SimpleGraphQLServlet. The SimpleGraphQLServlet implementation is using the Java.Util.Optional class but this class is not found in java 7 library. I can't upgrade my project java version to 8. Can anyone please provide me a solution to this problem.

(This question is not duplicate as intelliJ Optional class issue. This is related to Graphql library)

2
  • 1
    @ThomasBöhm This question does not need code. It presents the exact error message and the environment in which it happens. Commented Oct 30, 2017 at 22:52
  • graphql-java was Java 6 compatible up until version 3, I believe. So you could stick to 2.x branch for compatibility...
    – kaqqao
    Commented Nov 10, 2017 at 14:07

1 Answer 1

3

Streams and Optional were added only in Java 8. You may be able to use the streamsupport library, which provides a backport into the java.util space.

Note that using this library makes it likely that you'll have problems running on Java 8, and it's not exactly compatible, so if it's actually absolutely impossible to use Java 8, then you can try that, but keep in mind Java 9 is now out and Java 7 is obsolete.

Edit: I have not used streamsupport, and it appears that I incorrectly interpreted the documentation (it's not an exact backport), so this option may not work with a precompiled jar. In any case, moving to a modern platform is by far the best solution.

3
  • 1
    FWIW, the streamsupport backport lives in the java8.util package (i.e., exactly not in java.util for obvious reasons) Commented Oct 31, 2017 at 14:01
  • Thanks Chrylis for reply!! All our production servers are running on java 7 so upgrading to java 8 or 9 will be a huge effort. Any help on the Graphql java 7 compatible version maven dependency? Commented Oct 31, 2017 at 16:08
  • @KishoreJosyula Java 7 is now obsolete. It's time to upgrade. Perhaps moving to a lighterweight deployment set up such as Spring Boot provides would help. Commented Oct 31, 2017 at 20:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.