Java lang IllegalAccess on collecting Guava Immutable Table via HashBasedTable accumulator -


error while executing below code,

caused by: java.lang.illegalaccesserror: tried access class com.google.common.collect.abstracttable class

 immutabletable.copyof(listitemstoprocess.parallelstream()                     .map(item ->                             processorinstanceprovider.getinstance()                             .buildimmutabletable(item))                     .collect(() -> hashbasedtable.create(),                             hashbasedtable::putall,                              hashbasedtable<integer, string,                                 boolean>::putall)                     ); 

error in coming on - hashbasedtable::putall using oracle's 1.8 jre

this compiler bug, related reports are

  • jdk-8152643: “javac compiles method reference allows results in illegalaccesserror”
  • jdk-8059632: “method reference compilation uses incorrect qualifying type”

note first report has status “fixed in 8u102”, downloading jdk8u102 solve issue. of course, when using compiler other javac, e.g. ecj, have ensure that compiler date well.

in either case, have recompile source code, compiler issue. then, compiled code should work older jres.


to explain issue, normally, invocations should encoded byte code using compile-time type of receiver (or explicit type in case of static methods), regardless of declaring type of actual method implementation. if have public class a inheriting public method foo non-public class b, invocation of a.foo should encoded a.foo rather b.foo. ordinary invocations, compilers work way, method references, javac (and afaik older versions of ecj) failed correctly. when encountering class trying access b.foo directly without having access b, illegalaccesserror thrown.

it works when using lambda expression instead, then, invocation compiled ordinary invocation instruction, compiler works correctly, within synthetic method , reference synthetic method used when constructing instance of functional interface @ runtime. since synthetic method recides within same class, it’s accessible.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -