Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows][9.1.6.0] Script output redirection fails #4550

Open
TheSynthMaster opened this issue Mar 28, 2017 · 9 comments
Open

[Windows][9.1.6.0] Script output redirection fails #4550

TheSynthMaster opened this issue Mar 28, 2017 · 9 comments
Labels

Comments

@TheSynthMaster
Copy link

TheSynthMaster commented Mar 28, 2017

Environment

jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 Java HotSpot(TM) Client VM 23.3-b01 on 1.7.0_07-b10 +jit [mswin32-x86]

Using rails 5.0.1

Behaviour

Launching a script from command line and redirecting the output to a file give the following error:

C:\jrails4_update\applications\datawarehouse>jruby import_accounts.rb > ppp.txt

LoadError: load error: ./config/config -- java.lang.NullPointerException: charset
require at org/jruby/RubyKernel.java:959
require at C:/jrails4_update/jruby-9.1.6.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:55

at import_accounts.rb:5

Without redirection the script works as expected

@kares
Copy link
Member

kares commented May 29, 2017

interesting and quite a piece gone wrong, @PanDar1 any chance you test out 9.1.9 if its still there?
... if so we need a way to reproduce - ideally a minimalistic .rb file (based on import_accounts.rb)

@kares kares added the windows label May 29, 2017
@TheSynthMaster
Copy link
Author

I tried on 9.1.8.0, still present... do not currently have a 9.1.9 installed...

@kares
Copy link
Member

kares commented May 30, 2017

@PanDar1 thanks, how about the other part I have asked for (we do not know what's in the script) :

... if so we need a way to reproduce - ideally a minimalistic .rb file (based on import_accounts.rb)

@TheSynthMaster
Copy link
Author

TheSynthMaster commented May 30, 2017

Ok, I'm able to replicate the error with this:

require 'rubygems'
require 'active_record'
require 'yaml'
require 'logger'
require 'c:/jrails4_update/jruby-9.1.6.0/lib/ojdbc7.jar'
@config_db = YAML::load(File.open("./config/database.yml"))

the error arise with the last line

contents of database.yml follows:

datasource:
adapter: oracle_enhanced
database: ASESTERO
username: admin
password: *********

Error:

Unhandled Java exception: java.lang.NullPointerException: charset
java.lang.NullPointerException: charset
at java/io/InputStreamReader:-1
readerFor at org/jruby/ext/psych/PsychParser.java:165
parse at org/jruby/ext/psych/PsychParser.java:177
call at org/jruby/ext/psych/PsychParser$INVOKER$i$parse.gen:-1
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:358
call at org/jruby/runtime/callsite/CachingCallSite.java:195
processCall at org/jruby/ir/interpreter/InterpreterEngine.java:324
interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:
73
INTERPRET_METHOD at org/jruby/internal/runtime/methods/MixedModeIRMethod.ja
va:109
call at org/jruby/internal/runtime/methods/MixedModeIRMethod.ja
va:95
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:298
callBlock at org/jruby/runtime/callsite/CachingCallSite.java:79
call at org/jruby/runtime/callsite/CachingCallSite.java:83
interpret at org/jruby/ir/instructions/CallBase.java:428
processCall at org/jruby/ir/interpreter/InterpreterEngine.java:356
interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:
73
interpret at org/jruby/ir/interpreter/InterpreterEngine.java:90
INTERPRET_METHOD at org/jruby/internal/runtime/methods/MixedModeIRMethod.ja
va:214
call at org/jruby/internal/runtime/methods/MixedModeIRMethod.ja
va:200
call at org/jruby/internal/runtime/methods/DynamicMethod.java:2
08
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:358
call at org/jruby/runtime/callsite/CachingCallSite.java:195
processCall at org/jruby/ir/interpreter/InterpreterEngine.java:324
interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:
73
interpret at org/jruby/ir/interpreter/InterpreterEngine.java:84
INTERPRET_METHOD at org/jruby/internal/runtime/methods/MixedModeIRMethod.ja
va:179
call at org/jruby/internal/runtime/methods/MixedModeIRMethod.ja
va:165
call at org/jruby/internal/runtime/methods/DynamicMethod.java:2
00
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:338
call at org/jruby/runtime/callsite/CachingCallSite.java:163
invokeOther12:load at bug.rb:6

at bug.rb:6
invokeWithArguments at java/lang/invoke/MethodHandle:-1
load at org/jruby/ir/Compiler.java:111
runScript at org/jruby/Ruby.java:846
runNormally at org/jruby/Ruby.java:761
runNormally at org/jruby/Ruby.java:779
runFromMain at org/jruby/Ruby.java:592
doRunFromMain at org/jruby/Main.java:425
internalRun at org/jruby/Main.java:313
run at org/jruby/Main.java:242
main at org/jruby/Main.java:204

@headius
Copy link
Member

headius commented May 31, 2017

@PanDar1 That helps! It seems to be breaking inside psych. I'll have a look at that.

@headius
Copy link
Member

headius commented May 31, 2017

Ok, so the basic problem is that it's trying to get a charset from the IO you pass in, via getReadEncoding. However the encoding that's being returned does not have an equivalent Java Charset, so it's null, so this blows up.

This combination of encodings causes a similar result:

$ jruby -e "file = File.open('.travis.yml', 'r:Windows-1252:Windows-1252'); p JRuby.reference(file).getReadEncoding.charset"
nil

So a short term fix for you might be to specify encodings here that we know work. I assume your YAML file is in UTF-8 (or simply 7-bit US-ASCII) so try doing this in your code:

file = File.open("./config/database.yml", "r:UTF-8:UTF-8")
@config_db = YAML::load(file)

I will file the Psych issue over there and see about fixing it.

@TheSynthMaster
Copy link
Author

Well, I have worked around the bug by removing the redirection completely and writing on a file from the script, using this method...

def to_log(msg)
puts msg
File.open(@logfile, 'a') { |file| file.write(msg + "\n") }
end

but I will give your workaround a try, thanks!

@headius
Copy link
Member

headius commented May 31, 2017

You can also read the yaml content completely and pass the string to YAML.load, to avoid the IO/encoding dance.

@headius
Copy link
Member

headius commented May 31, 2017

This is fixed in ruby/psych#319 and once there's a psych release we'll roll it into JRuby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants