You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
9.2.8 -- java.util.logging.ConsoleHandler.setOutputStream works in java 8 but not 11 (impacts trinidad) #5821
changed the title [-]java.util.logging.ConsoleHandler.setOutputStream works in java 8 but not 11 (impacts trinidad)[/-][+]9.2.8 -- java.util.logging.ConsoleHandler.setOutputStream works in java 8 but not 11 (impacts trinidad)[/+]on Aug 9, 2019
JUL = Java::JavaUtilLogging
class Poo < JUL::ConsoleHandler
def setOutputStream(stream)
super(stream)
end
end
Poo.new.setOutputStream(java.lang.System.out)
Whoops sorry, the above chicanery works in 8 but not 11, so inheritance may need some work too.
irb(main):057:0> Poo.new.setOutputStream(java.lang.System.out)
?[1mTraceback?[m (most recent call last):
7: from uri:classloader:/META-INF/jruby.home/bin/jirb:13:in `<main>'
6: from org/jruby/RubyKernel.java:1193:in `catch'
5: from org/jruby/RubyKernel.java:1193:in `catch'
4: from org/jruby/RubyKernel.java:1425:in `loop'
3: from org/jruby/RubyKernel.java:1061:in `eval'
2: from (irb):57:in `evaluate'
1: from (irb):52:in `setOutputStream'
?[1mNoMethodError (?[4msuper: no superclass method `setOutputStream' for #<Poo:0x2bcb1414>?[0;1m)?[m
?[1mDid you mean? setOutputStream?[m
The issue here is that setOutputStream has protected access (on the superclass StreamHandler), and on Java 9+ we are somewhat limited on what we can do to access non-visible stuff. Our choice up to this point has been to not try to force accessibility if the module is not open, since it will produce those ugly warnings people keep complaining about.
So the simple answer is that you need to open up that package and that module to JRuby.
Unfortunately, there's a bug in JRuby that prevents this from working:
$ JAVA_OPTS="--add-opens java.logging/java.util.logging=org.jruby.dist" \
jruby -e 'java.util.logging.ConsoleHandler.new.setOutputStream(File.open("blah.txt", "w").to_outputstream)'
NoMethodError: undefined method `setOutputStream' for #<Java::JavaUtilLogging::ConsoleHandler:0x2fac80a8>
<main> at -e:1
The bug in question is that when testing for accessibility, we ask the module subsystem if the target method's class's package is open but do not pass a module or class from JRuby (in the standard JRuby distribution, this module is org.jruby.dist). So even though it has been opened up to JRuby, it's not open to "everyone" and the check fails.
I have a fix for this that's fairly simple:
diff --git a/core/src/main/java/org/jruby/javasupport/binding/Initializer.java b/core/src/main/java/org/jruby/javasupport/binding/Initializer.java
index 70146e5171..5e2834b9d3 100644
--- a/core/src/main/java/org/jruby/javasupport/binding/Initializer.java+++ b/core/src/main/java/org/jruby/javasupport/binding/Initializer.java@@ -540,7 +542,7 @@ public abstract class Initializer {
if ( Modifier.isPrivate(mod) ) continue;
// Skip protected methods if we can't set accessible
- if ( !Modifier.isPublic(mod) && !Modules.trySetAccessible(method)) continue;+ if ( !Modifier.isPublic(mod) && !Modules.trySetAccessible(method, Ruby.class)) continue;
// ignore bridge methods because we'd rather directly call methods that this method
// is bridging (and such methods are by definition always available.)
I'm trying to figure out if there's any way to work around this. It's possible to specify at the command line that a module/package should be exported to "ALL-UNNAMED" modules, but there does not appear to be a way to open it up to "everyone".
BTW -- My goal here is to get a large JRuby project running on Java 11. This task seem rougher than I would have thought. I discovered this trying to get trinidad up.
In file gem_home\gems\trinidad-1.5.0.B2\lib\trinidad\lifecycle\logging.rb changing:
def self.new_console_handler(stream)
handler = JUL::ConsoleHandler.new # sets output stream to System.err
handler.writer = nil if handler.respond_to?(:writer=) # avoid writer.close
if handler.respond_to?(:sealed) && handler.sealed
handler.sealed = false # avoid manager security checks
handler.setOutputStream(stream) # closes previous writer if != null
handler.sealed = true
else
handler.setOutputStream(stream)
end
handler
end
To:
def self.new_console_handler(stream)
handler = JUL::ConsoleHandler.new # sets output stream to System.err
arg_clazzes = [java.io.OutputStream].to_java(java.lang.Class)
stream_method = JUL::StreamHandler.java_class.to_java.getDeclaredMethod(:setOutputStream, arg_clazzes)
stream_method.setAccessible(true)
handler.writer = nil if handler.respond_to?(:writer=) # avoid writer.close
if handler.respond_to?(:sealed) && handler.sealed
handler.sealed = false # avoid manager security checks
stream_method.invoke(handler,stream) # closes previous writer if != null
handler.sealed = true
else
stream_method.invoke(handler,stream)
end
puts "All dun Cris! #{stream}"
handler
end
Fixes that problem, but opens the next one in the chain.
@cshupp1 Try out a newer snapshot build (once that commit passes in Travis) and let me know that you can open up the package in question. This should work for any other packages that are having trouble.
I am also discussing with @enebo and @kares how we can make this process easier. Right now, if we won't be able to set a method accessible, we quietly refuse to bind it. I'm proposing that instead, we should install a dummy method that errors with information about how to open up the given package.
@headius -- Will do. I see Nexus still doesn't have it yet and I will definitely be w/o internet on Monday and Tuesday of next weekl. @enebo tells me you hope to release 9.2.8 on Monday. If I see that does happen I will just try the released version when I return.
@cshupp1 The build went wonky for some reason but I've kicked it and hopefully it will deploy the snapshots now.
Note I also filed #5824 which discusses the long-forgotten "@file" feature of the standard java executable; you can put whatever JVM options you want in "file" and they'll be added to your command line if you do jruby -J@file ... or similar. I am proposing that we should have a standard per-directory (and perhaps also another globally in your home dir) that will automatically get picked up, but until then you can still use explicit flags plus an "@file" to make these add-opens easier to stomach.
@headius everything worked for me on java 11 with trinidad
I used the following opts:
set JAVA_OPTS=%JAVA_OPTS% --add-opens java.base/java.io=org.jruby.dist
set JAVA_OPTS=%JAVA_OPTS% --add-opens java.base/java.nio.channels=org.jruby.dist
set JAVA_OPTS=%JAVA_OPTS% --add-opens java.base/sun.nio.ch=org.jruby.dist
set JAVA_OPTS=%JAVA_OPTS% --add-opens java.base/sun.nio.ch=org.jruby.core <-- says it can't find this one though even though some output calls for it
set JAVA_OPTS=%JAVA_OPTS% --add-opens java.logging/java.util.logging=org.jruby.dist
The issue that followed (when I was testing with the snapshot build)
was my inability to get the following require to load:
require 'bundler/setup'
But this issue is no more!
Of course since 9.2.8 is released I am able to keep jruby-jars consistent with the jar file I pass to java, so that might have been it.
@cshupp1 The org.jruby.core module is supposed to be associated with the Maven jruby-core jar, which someone from the Java side of things might be using to embed JRuby. However it seems like we may never have done this; I will investigate that separately. As long as you are using JRuby via the standard distribution, you should only need org.jruby.dist.
Activity
[-]java.util.logging.ConsoleHandler.setOutputStream works in java 8 but not 11 (impacts trinidad)[/-][+]9.2.8 -- java.util.logging.ConsoleHandler.setOutputStream works in java 8 but not 11 (impacts trinidad)[/+]cshupp1 commentedon Aug 9, 2019
Chicanery like this seems to work:
cshupp1 commentedon Aug 9, 2019
Whoops sorry, the above chicanery works in 8 but not 11, so inheritance may need some work too.
headius commentedon Aug 9, 2019
The issue here is that
setOutputStreamhas protected access (on the superclass StreamHandler), and on Java 9+ we are somewhat limited on what we can do to access non-visible stuff. Our choice up to this point has been to not try to force accessibility if the module is not open, since it will produce those ugly warnings people keep complaining about.So the simple answer is that you need to open up that package and that module to JRuby.
Unfortunately, there's a bug in JRuby that prevents this from working:
The bug in question is that when testing for accessibility, we ask the module subsystem if the target method's class's package is open but do not pass a module or class from JRuby (in the standard JRuby distribution, this module is
org.jruby.dist). So even though it has been opened up to JRuby, it's not open to "everyone" and the check fails.I have a fix for this that's fairly simple:
I'm trying to figure out if there's any way to work around this. It's possible to specify at the command line that a module/package should be exported to "ALL-UNNAMED" modules, but there does not appear to be a way to open it up to "everyone".
cshupp1 commentedon Aug 9, 2019
@headius But I assume the inheritance example, provided above, you would intend to support right?
cshupp1 commentedon Aug 9, 2019
BTW -- My goal here is to get a large JRuby project running on Java 11. This task seem rougher than I would have thought. I discovered this trying to get trinidad up.
In file gem_home\gems\trinidad-1.5.0.B2\lib\trinidad\lifecycle\logging.rb changing:
To:
Fixes that problem, but opens the next one in the chain.
headius commentedon Aug 9, 2019
@cshupp1 It is, and it appears that my fix makes that example work too!
I have not found any way to work around the bug I patched above, unfortunately. I will make the change to JRuby and push it to master.
Provide a JRuby class when checking accessibility.
headius commentedon Aug 9, 2019
@cshupp1 Try out a newer snapshot build (once that commit passes in Travis) and let me know that you can open up the package in question. This should work for any other packages that are having trouble.
I am also discussing with @enebo and @kares how we can make this process easier. Right now, if we won't be able to set a method accessible, we quietly refuse to bind it. I'm proposing that instead, we should install a dummy method that errors with information about how to open up the given package.
cshupp1 commentedon Aug 9, 2019
@headius -- Will do. I see Nexus still doesn't have it yet and I will definitely be w/o internet on Monday and Tuesday of next weekl. @enebo tells me you hope to release 9.2.8 on Monday. If I see that does happen I will just try the released version when I return.
headius commentedon Aug 9, 2019
@cshupp1 The build went wonky for some reason but I've kicked it and hopefully it will deploy the snapshots now.
Note I also filed #5824 which discusses the long-forgotten "@file" feature of the standard
javaexecutable; you can put whatever JVM options you want in "file" and they'll be added to your command line if you dojruby -J@file ...or similar. I am proposing that we should have a standard per-directory (and perhaps also another globally in your home dir) that will automatically get picked up, but until then you can still use explicit flags plus an "@file" to make theseadd-openseasier to stomach.cshupp1 commentedon Aug 14, 2019
@headius everything worked for me on java 11 with trinidad
I used the following opts:
The issue that followed (when I was testing with the snapshot build)
was my inability to get the following require to load:
But this issue is no more!
Of course since 9.2.8 is released I am able to keep jruby-jars consistent with the jar file I pass to java, so that might have been it.
Thanks!
Cris
headius commentedon Aug 21, 2019
@cshupp1 The
org.jruby.coremodule is supposed to be associated with the Mavenjruby-corejar, which someone from the Java side of things might be using to embed JRuby. However it seems like we may never have done this; I will investigate that separately. As long as you are using JRuby via the standard distribution, you should only need org.jruby.dist.Move all JI setAccessible to trySetAccessible.
Provide a JRuby class when checking accessibility.
Move all JI setAccessible to trySetAccessible.