From 370d2555c7b898ea62b6d4896e092f35f56f6c0f Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Thu, 31 Jul 2014 14:42:51 +0000
Subject: [PATCH] Notes and logging re: compiling with Java 8

---
 build.properties                              | 21 +++++++++++++++++++
 .../i2p/router/tunnel/pool/BuildExecutor.java | 21 ++++++++++++++++++-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/build.properties b/build.properties
index d31351d0b8..8ee39009bf 100644
--- a/build.properties
+++ b/build.properties
@@ -46,6 +46,27 @@ javac.version=1.6
 # This one keeps gcj a lot quieter
 #javac.compilerargs=-warn:-unchecked,raw,unused,serial
 
+#
+# Note to packagers, embedders, distributors:
+#
+# Strictly speaking, you must either use the compiler for the minimum Java version you are
+# targeting (default 1.6, see above), or specify a bootclasspath, which means you need
+# the JRE for the target version installed as well.
+#
+# However, in practice, you can compile with 1.7 and target 1.6 without specifying a bootclasspath,
+# and it all works fine.
+#
+# But you cannot compile with 1.8 and target 1.6 or 1.7 without bootclasspath,
+# or your users will get runtime errors.
+# Below is an example of a bootclasspath that works on Ubuntu.
+#
+# For more info:
+#    http://zzz.i2p/topics/1668
+#    https://gist.github.com/AlainODea/1375759b8720a3f9f094
+#
+#javac.compilerargs=-bootclasspath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/jce.jar
+
+
 ### UnitTests ##
 # Location of the libraries required for the ScalaTest tests.
 # Define this in override.properties or pass in on the command line.
diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java b/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java
index 3ff080fd7f..b771589a1f 100644
--- a/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java
+++ b/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java
@@ -285,6 +285,26 @@ class BuildExecutor implements Runnable {
 
     public void run() {
         _isRunning = true;
+        try {
+            run2();
+        } catch (NoSuchMethodError nsme) {
+            // http://zzz.i2p/topics/1668
+            // https://gist.github.com/AlainODea/1375759b8720a3f9f094
+            // at ObjectCounter.objects()
+            String s = "Fatal error:" +
+                       "\nJava 8 compiler used with JRE version " + System.getProperty("java.version") +
+                       " and no bootclasspath specified." +
+                       "\nUpdate to Java 8 or contact packager." +
+                       "\nStop I2P now, it will not build tunnels.";
+            _log.log(Log.CRIT, s, nsme);
+            System.out.println(s);
+            throw nsme;
+        } finally {
+            _isRunning = false;
+        }
+    }
+
+    private void run2() {
         List<TunnelPool> wanted = new ArrayList<TunnelPool>(MAX_CONCURRENT_BUILDS);
         List<TunnelPool> pools = new ArrayList<TunnelPool>(8);
         
@@ -423,7 +443,6 @@ class BuildExecutor implements Runnable {
         
         if (_log.shouldLog(Log.WARN))
             _log.warn("Done building");
-        _isRunning = false;
     }
     
     /**
-- 
GitLab