jruby / activerecord-jdbc-adapter

JRuby's ActiveRecord adapter using JDBC.
BSD 2-Clause "Simplified" License
461 stars 385 forks source link

Unhandled Java exception: java.lang.NullPointerException when calling `exec_update` #1033

Closed donv closed 5 years ago

donv commented 5 years ago

Hi!

Using JRuby 9.2.8.0 + ARJDBC 52.3. This works with MRI 2.5 but gives NPE with JRuby.

Any idea what is going on?

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'activerecord', '~>5.2.3'
  platform(:jruby) { gem 'activerecord-jdbcsqlite3-adapter', '~>52.3' }
  platform(:mri) { gem 'sqlite3' }
end

require 'active_record'

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.connection.create_table('comments') { |t| t.text 'comment', null: false }

comment = 'æøåæøåæøå'

ActiveRecord::Base.connection.exec_update("INSERT INTO comments(comment) VALUES ($1)", 'INSERT', [[nil, comment]])
rs = ActiveRecord::Base.connection.exec_query("SELECT * FROM comments WHERE comment=$1", 'SELECT', [[nil, comment]])
pp rs.to_a
$ chruby ruby-2.5
$ ruby exec_update.rb 
[{"id"=>1, "comment"=>"æøåæøåæøå"}]
$ chruby jruby-9.2.8.0
$ ruby exec_update.rb 
Unhandled Java exception: java.lang.NullPointerException
java.lang.NullPointerException: null
           attributeSQLType at arjdbc/jdbc/RubyJdbcConnection.java:2682
            internedTypeFor at arjdbc/jdbc/RubyJdbcConnection.java:2689
       jdbcTypeForAttribute at arjdbc/jdbc/RubyJdbcConnection.java:2662
      setStatementParameter at arjdbc/jdbc/RubyJdbcConnection.java:2554
     setStatementParameters at arjdbc/jdbc/RubyJdbcConnection.java:2544
                       call at arjdbc/jdbc/RubyJdbcConnection.java:989
                       call at arjdbc/jdbc/RubyJdbcConnection.java:983
             withConnection at arjdbc/jdbc/RubyJdbcConnection.java:3466
             withConnection at arjdbc/jdbc/RubyJdbcConnection.java:3432
    execute_prepared_update at arjdbc/jdbc/RubyJdbcConnection.java:983
                       call at arjdbc/jdbc/RubyJdbcConnection$INVOKER$i$2$0$execute_prepared_update.gen:-1
               cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:396
                       call at org/jruby/runtime/callsite/CachingCallSite.java:205
                processCall at org/jruby/ir/interpreter/InterpreterEngine.java:325
                  interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:72
            INTERPRET_BLOCK at org/jruby/ir/interpreter/Interpreter.java:114
            commonYieldPath at org/jruby/runtime/MixedModeIRBlockBody.java:151
              yieldSpecific at org/jruby/runtime/IRBlockBody.java:89
              yieldSpecific at org/jruby/runtime/Block.java:139
              yieldSpecific at org/jruby/ir/runtime/IRRuntimeHelpers.java:481
                  interpret at org/jruby/ir/instructions/YieldInstr.java:76
             processOtherOp at org/jruby/ir/interpreter/StartupInterpreterEngine.java:178
                  interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:104
            INTERPRET_BLOCK at org/jruby/ir/interpreter/Interpreter.java:114
            commonYieldPath at org/jruby/runtime/MixedModeIRBlockBody.java:151
              yieldSpecific at org/jruby/runtime/IRBlockBody.java:89
              yieldSpecific at org/jruby/runtime/Block.java:139
              yieldSpecific at org/jruby/ir/runtime/IRRuntimeHelpers.java:481
                  interpret at org/jruby/ir/instructions/YieldInstr.java:76
             processOtherOp at org/jruby/ir/interpreter/StartupInterpreterEngine.java:178
                  interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:104
           INTERPRET_METHOD at org/jruby/internal/runtime/methods/MixedModeIRMethod.java:105
                       call at org/jruby/internal/runtime/methods/MixedModeIRMethod.java:92
                       call at org/jruby/internal/runtime/methods/AliasMethod.java:135
                       call at org/jruby/runtime/callsite/CachingCallSite.java:84
                   callIter at org/jruby/runtime/callsite/CachingCallSite.java:93
                  interpret at org/jruby/ir/instructions/CallBase.java:537
                processCall at org/jruby/ir/interpreter/InterpreterEngine.java:361
                  interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:72
            INTERPRET_BLOCK at org/jruby/ir/interpreter/Interpreter.java:114
            commonYieldPath at org/jruby/runtime/MixedModeIRBlockBody.java:151
                    doYield at org/jruby/runtime/IRBlockBody.java:187
                      yield at org/jruby/runtime/BlockBody.java:116
                      yield at org/jruby/runtime/Block.java:170
                      yield at org/jruby/ir/runtime/IRRuntimeHelpers.java:477
                  interpret at org/jruby/ir/instructions/YieldInstr.java:85
             processOtherOp at org/jruby/ir/interpreter/StartupInterpreterEngine.java:178
                  interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:104
           INTERPRET_METHOD at org/jruby/internal/runtime/methods/MixedModeIRMethod.java:105
                       call at org/jruby/internal/runtime/methods/MixedModeIRMethod.java:92
                       call at org/jruby/runtime/callsite/CachingCallSite.java:84
                   callIter at org/jruby/runtime/callsite/CachingCallSite.java:93
                  interpret at org/jruby/ir/instructions/CallBase.java:537
                processCall at org/jruby/ir/interpreter/InterpreterEngine.java:361
                  interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:72
           INTERPRET_METHOD at org/jruby/internal/runtime/methods/MixedModeIRMethod.java:105
                       call at org/jruby/internal/runtime/methods/MixedModeIRMethod.java:92
            unresolvedSuper at org/jruby/ir/runtime/IRRuntimeHelpers.java:1193
                  interpret at org/jruby/ir/instructions/UnresolvedSuperInstr.java:102
                processCall at org/jruby/ir/interpreter/InterpreterEngine.java:361
                  interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:72
           INTERPRET_METHOD at org/jruby/internal/runtime/methods/MixedModeIRMethod.java:105
                       call at org/jruby/internal/runtime/methods/MixedModeIRMethod.java:92
               cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:332
                       call at org/jruby/runtime/callsite/CachingCallSite.java:86
                   callIter at org/jruby/runtime/callsite/CachingCallSite.java:93
                  interpret at org/jruby/ir/instructions/CallBase.java:537
                processCall at org/jruby/ir/interpreter/InterpreterEngine.java:361
                  interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:72
                  interpret at org/jruby/ir/interpreter/InterpreterEngine.java:98
           INTERPRET_METHOD at org/jruby/internal/runtime/methods/MixedModeIRMethod.java:236
                       call at org/jruby/internal/runtime/methods/MixedModeIRMethod.java:223
                       call at org/jruby/internal/runtime/methods/DynamicMethod.java:216
               cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:418
                       call at org/jruby/runtime/callsite/CachingCallSite.java:236
  invokeOther43:exec_update at exec_update.rb:17
                     <main> at exec_update.rb:17
        invokeWithArguments at java/lang/invoke/MethodHandle.java:627
                       load at org/jruby/ir/Compiler.java:89
                  runScript at org/jruby/Ruby.java:854
                runNormally at org/jruby/Ruby.java:777
                runNormally at org/jruby/Ruby.java:795
                runFromMain at org/jruby/Ruby.java:607
              doRunFromMain at org/jruby/Main.java:412
                internalRun at org/jruby/Main.java:304
                        run at org/jruby/Main.java:234
                       main at org/jruby/Main.java:206