java-8 – Class does not compile when using new java 8 'Optional' feature

Question:

Good afternoon

I'm using play 2.5.4 with java 8 v01.08.91 And when using some features of java 8 such as the 'Optional' class with the 'ifPresent', 'isPresent' or 'get' methods, the following error appears when compiling the java classes

"java.lang.ClassCastException: javassist.bytecode.InterfaceMethodrefInfo cannot be cast to javassist.bytecode.MethodrefInfo"

Specifically, this is the snippet of code that gives the problem:

Optional<AppMobileWrapper> lastSend = appsWrapper.stream()
            .max(Comparator.comparing(f -> f.changeDate));

    lastSend.ifPresent(appMobileWrapper -> {
        returnWrapper.lastDate = DateUtils.currentDateNoTimeZoneString(appMobileWrapper.changeDate);
    });

I've tried to do everything, I'm looking for a solution for hours. My play version is updated, java version updated, environment variables are ok and I even tried adding the updated javassist dependency in the sbt dependencies and it still doesn't work at all. Has anyone experienced this problem?

Answer:

After an upgrade in play/java, I solved a similar problem following the instructions described in this project issue . In my case, I updated javassist in project/plugins.sbt :

libraryDependencies += "org.javassist" % "javassist" % "3.20.0-GA"

Since it would be used by an sbt plugin at compile time and not runtime.

Scroll to Top