Nuix / Digest-Helper

Helper class for Nuix digest list manipulation
Apache License 2.0
0 stars 1 forks source link

NullPointerException with Nuix 9.6 and Windows Server 2019 #1

Open irene-wilson opened 2 years ago

irene-wilson commented 2 years ago

Hello, I have a script running in Nuix 9.6 and calling DigestHelper.rb_ and I get a NullPointerException. It crashes within def initialize(db_path=nil):

def initialize(db_path=nil)
        @strip_regex = /[^a-f0-9]+/i
        #Uses provided db_path value or generate a new random path
        @db_tmpfile = db_path || "#{Dir.tmpdir}\\#{Time.now.strftime("%Y%m%d_%H%M%S")}_tmp.db".gsub("/","\\")
        puts "Temp db: #{@db_tmpfile}"
        @iutil = $utilities.getItemUtility
        puts "asd1"
        with_connection do |connection|
            puts "asd2"

The text asd1 appears, but not asd2.

Here is the detail of the error:

Script failed due to an error: org.jruby.embed.EvalFailedException: java.lang.NullPointerException at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:137) at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:118) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at com.nuix.script.e.a(SourceFile:53) at java.base/java.security.AccessController.doPrivileged(Native Method) at com.nuix.script.e.a(SourceFile:50) at com.sun.proxy.$Proxy79.eval(Unknown Source) at com.nuix.script.a.a(SourceFile:272) at com.nuix.investigator.script.m.e(SourceFile:314) at com.nuix.investigator.script.m.c(SourceFile:265) at com.nuix.investigator.script.m.doInBackground(SourceFile:168) at java.desktop/javax.swing.SwingWorker$1.call(SwingWorker.java:304) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.desktop/javax.swing.SwingWorker.run(SwingWorker.java:343) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829) Caused by: java.lang.NullPointerException at org.sqlite.SQLiteConfig.apply(org/sqlite/SQLiteConfig.java:220) at org.sqlite.SQLiteConnection.(org/sqlite/SQLiteConnection.java:67) at org.sqlite.jdbc3.JDBC3Connection.(org/sqlite/jdbc3/JDBC3Connection.java:28) at org.sqlite.jdbc4.JDBC4Connection.(org/sqlite/jdbc4/JDBC4Connection.java:21) at org.sqlite.JDBC.createConnection(org/sqlite/JDBC.java:115) at org.sqlite.JDBC.connect(org/sqlite/JDBC.java:90) at java.sql.DriverManager.getConnection(java/sql/DriverManager.java:677) at java.sql.DriverManager.getConnection(java/sql/DriverManager.java:228) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(jdk/internal/reflect/NativeMethodAccessorImpl.java:62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(jdk/internal/reflect/DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:566) at org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(org/jruby/javasupport/JavaMethod.java:426) at org.jruby.javasupport.JavaMethod.invokeStaticDirect(org/jruby/javasupport/JavaMethod.java:358) at RUBY.withconnection(C:/Users/Administrator/AppData/Roaming/Nuix/Scripts/DigestHelper.rb:186) at RUBY.initialize(C:/Users/Administrator/AppData/Roaming/Nuix/Scripts/DigestHelper.rb_:53) at org.jruby.RubyClass.newInstance(org/jruby/RubyClass.java:911) at org.jruby.RubyClass$INVOKER$i$newInstance.call(org/jruby/RubyClass$INVOKER$i$newInstance.gen) at RUBY.savefile(C:/Users/Administrator/AppData/Roaming/Nuix/Scripts/DigestHelper.rb:37) at RUBY.

(C:\Users\Administrator\AppData\Roaming\Nuix\Scripts\Swiss FTS - Custodian overlay export v04 TEST.rb:274) at org.jruby.Ruby.runInterpreter(org/jruby/Ruby.java:1240) at org.jruby.Ruby.runInterpreter(org/jruby/Ruby.java:1244) at org.jruby.embed.internal.EmbedEvalUnitImpl.run(org/jruby/embed/internal/EmbedEvalUnitImpl.java:118) at org.jruby.embed.jsr223.JRubyEngine.eval(org/jruby/embed/jsr223/JRubyEngine.java:118) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(jdk/internal/reflect/NativeMethodAccessorImpl.java:62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(jdk/internal/reflect/DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:566) at com.nuix.script.e.a(com/nuix/script/SourceFile:53) at java.security.AccessController.doPrivileged(Native Method) at com.nuix.script.e.a(com/nuix/script/SourceFile:50) at com.sun.proxy.$Proxy79.eval(com/sun/proxy/$Proxy79) at com.nuix.script.a.a(com/nuix/script/SourceFile:272) at com.nuix.investigator.script.m.e(com/nuix/investigator/script/SourceFile:314) at com.nuix.investigator.script.m.c(com/nuix/investigator/script/SourceFile:265) at com.nuix.investigator.script.m.doInBackground(com/nuix/investigator/script/SourceFile:168) at javax.swing.SwingWorker$1.call(javax/swing/SwingWorker.java:304) at java.util.concurrent.FutureTask.run(java/util/concurrent/FutureTask.java:264) at javax.swing.SwingWorker.run(javax/swing/SwingWorker.java:343) at java.util.concurrent.ThreadPoolExecutor.runWorker(java/util/concurrent/ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run(java/util/concurrent/ThreadPoolExecutor.java:628) at java.lang.Thread.run(java/lang/Thread.java:829)

Any idea how to fix this?

Thanks in advance and kind regards,

Irène

JuicyDragon commented 2 years ago

Hello @irene-wilson can you share the copy of DigestHelper.rb_ that you are using? The error says it is happening on line 186 within the with_connection method:

at RUBY.with_connection(C:/Users/Administrator/AppData/Roaming/Nuix/Scripts/DigestHelper.rb_:186)

When I go look at that line it is within a different method: https://github.com/Nuix/Digest-Helper/blob/master/DigestHelper.rb_#L186

with_connection method: https://github.com/Nuix/Digest-Helper/blob/master/DigestHelper.rb_#L179-L183

I'd like to determine which line specifically within the with_connection method is throwing the error as that will help narrow things down. Thanks!

irene-wilson commented 2 years ago

DigestHelper.zip Sorry, here is the file. We modified it slightly in an attempt to pin point the issue.

In our code, these lines are calling the DigestHelper:

# Creating a digest list with the top-level items from the new Relativity export(s)
digestListName = "#{projectName}_#{Time.now.strftime "%Y%m%d"}_temp_overlay"

digest_file = "C:\\ProgramData\\Nuix\\Digest Lists\\#{digestListName}.hash"
DigestHelper.save_file(digest_file, $utilities.getItemUtility.deduplicate($current_case.search(queryDigestListScope)) )

I checked and there are items returned by this query. I even adjusted the query with "md5:*" to ensure all items would have an MD5, but the error still occurs. The script works fine on older versions though.

Thanks a lot for your help!

JuicyDragon commented 2 years ago

Depending on what version you are coming from the Java Runtime Environment packaged with Nuix went from (I believe) Java 8 to Java 11. It appears that something must have subtly changed with obtaining the the SQLite JDBC connection. If you change this line:

connection = java.sql.DriverManager.getConnection("jdbc:sqlite:#{@db_tmpfile}", "", "")

to this

connection = java.sql.DriverManager.getConnection("jdbc:sqlite:#{@db_tmpfile}")

It looks like things work again. The 2 additional arguments are for specifying a username and password for the database. It's been a long time so I don't recall why I was specifying the blank values, but it seems that doing so now causes this issue.

JuicyDragon commented 2 years ago

I think this is an even better solution and what I will likely incorporate into this repository:

def with_connection(&block)
    if NUIX_VERSION[0].to_i < 9
        connection = java.sql.DriverManager.getConnection("jdbc:sqlite:#{@db_tmpfile}", "", "")
    else
        connection = java.sql.DriverManager.getConnection("jdbc:sqlite:#{@db_tmpfile}")
    end
    yield(connection)
    connection.close if !connection.nil?
end

This looks to keep things working from Nuix 6.2 to Nuix 9.6. The difference is I do a quick check as to whether the NUIX_VERSION string starts with a 9 or not and use that to determine which approach I use.