javacompiler-errorsguavamachine-codegcj

gcj Error - cannot find file for class java.util.function.Predicate


I have a java code which I have to use guava23.0.jar as an external library. More specifically, I need to have these imports:

import com.google.common.base.Charsets;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnel;
import com.google.common.hash.PrimitiveSink;

I build jar file of my code and now, I try to generate machine code using gcj. I tested the jar file, it works just fine and gives me the output. But, when trying to compile and generate machine code with gcj, it gives me several errors:

com/google/common/base/Predicate.java:0:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/Predicate.java: At top level:
com/google/common/base/Predicate.java:0:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/Predicate.java:0:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/Supplier.java: In class 'com.google.common.base.Absent':
com/google/common/base/Supplier.java: In method 'com.google.common.base.Absent.or(com.google.common.base.Supplier)':
In file included from com/google/common/base/Absent.java:60:0,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/Supplier.java:0:0: error: cannot find file for class java.util.function.Supplier
In file included from com/google/common/annotations/VisibleForTesting.java:2:0,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/Absent.java:60:0: error: cannot find file for class java.util.function.Supplier
com/google/common/base/Absent.java:60:0: error: cannot find file for class java.util.function.Supplier
com/google/common/base/Absent.java:60:0: error: cannot find file for class java.util.function.Supplier
com/google/common/base/Function.java: At top level:
In file included from com/google/common/base/Ascii.java:636:0,
                 from com/google/common/base/AbstractIterator.java:89,
                 from com/google/common/base/AbstractIterator.java:35,
                 from com/google/common/base/AbstractIterator.java:60,
                 from com/google/common/base/Absent.java:27,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/Function.java:0:0: error: cannot find file for class java.util.function.Function
In file included from com/google/common/base/Ascii.java:634:0,
                 from com/google/common/base/AbstractIterator.java:89,
                 from com/google/common/base/AbstractIterator.java:35,
                 from com/google/common/base/AbstractIterator.java:60,
                 from com/google/common/base/Absent.java:27,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
In file included from com/google/common/base/Ascii.java:640:0,
                 from com/google/common/base/AbstractIterator.java:89,
                 from com/google/common/base/AbstractIterator.java:35,
                 from com/google/common/base/AbstractIterator.java:60,
                 from com/google/common/base/Absent.java:27,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/Converter.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/Converter.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java: In class 'com.google.common.base.CaseFormat':
com/google/common/base/CaseFormat.java: In method 'com.google.common.base.CaseFormat.convert(com.google.common.base.CaseFormat,java.lang.String)':
In file included from com/google/common/base/CaseFormat.java:155:0,
                 from com/google/common/base/CaseFormat.java:101,
                 from com/google/common/base/CaseFormat.java:82,
                 from com/google/common/base/CaseFormat.java:74,
                 from com/google/common/base/CaseFormat.java:66,
                 from com/google/common/base/CaseFormat.java:47,
                 from com/google/common/base/Ascii.java:641,
                 from com/google/common/base/AbstractIterator.java:89,
                 from com/google/common/base/AbstractIterator.java:35,
                 from com/google/common/base/AbstractIterator.java:60,
                 from com/google/common/base/Absent.java:27,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/CaseFormat.java:130:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/CaseFormat.java:130:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/CharMatcher.java: In class 'com.google.common.base.CharMatcher$And':
com/google/common/base/CharMatcher.java: In method 'negate()':
In file included from com/google/common/base/CharMatcher.java:616:0,
                 from com/google/common/base/CaseFormat.java:30,
                 from com/google/common/base/CaseFormat.java:155,
                 from com/google/common/base/CaseFormat.java:101,
                 from com/google/common/base/CaseFormat.java:82,
                 from com/google/common/base/CaseFormat.java:74,
                 from com/google/common/base/CaseFormat.java:66,
                 from com/google/common/base/CaseFormat.java:47,
                 from com/google/common/base/Ascii.java:641,
                 from com/google/common/base/AbstractIterator.java:89,
                 from com/google/common/base/AbstractIterator.java:35,
                 from com/google/common/base/AbstractIterator.java:60,
                 from com/google/common/base/Absent.java:27,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/CharMatcher.java:1719:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/CharMatcher.java:1719: confused by earlier errors, bailing out

I don't get these errors in my other codes that include some other external jars than guava!


Solution

  • I assume that you are talking about the GCJ Java compiler that was part of the GCC compiler suite.

    I'm afraid, that GCJ relied on the GNU Classpath libraries, and those libraries didn't achieve full coverage of the Java 5 class libraries. Classpath development effort ground to a halt after Sun open-sourced Java 6.

    The code that you are trying to compile depends on Java 8 APIs. They were never implemented in Classpath. That is the root cause of the compilation errors you are getting.

    The GCJ toolchain is now effectively dead. As the Wikipedia page says:

    As of 2015, there were no new developments announced from GCJ and the product was in maintenance mode. GCJ was removed from the GCC trunk on September 30, 2016. Announcement of its removal was made with the release of the GCC 7.1, which does not contain it. GCJ remains part of GCC 6.

    If you are looking for a viable Java AOT (ahead of time) compiler, consider: