title: NullPointerException in Java script library
body: <p>I am making a first step into Java- trying to create a simple Java script library in Domino Designer 8.5.2 to perform SFTP file transfers using JSch 0.1.48. The library will be called from a LotusScript agent via LS2J. Here is my SFTP class from the script library, based on <a href="https://stackoverflow.com/a/2690960/461954">this SO answer</a>:</p>
  
  <pre><code>import com.jcraft.jsch.*;
  
  public class SFTP {
      public String GetFile(String host, String user, String pass, 
                            String localPath, String remotePath) {
          JSch jsch = new JSch();
          Session session = null;
          try {
              session = jsch.getSession(user, host, 22);
              session.setConfig("StrictHostKeyChecking", "no");
              session.setPassword(pass);
              session.connect();
              Channel channel = session.openChannel("sftp");
              channel.connect();
              ChannelSftp sftpChannel = (ChannelSftp) channel;
              sftpChannel.get(remotePath, localPath);
              sftpChannel.exit();
              session.disconnect();
          } catch (JSchException e) {
              e.printStackTrace();
          } catch (SftpException e) {
              e.printStackTrace();
          }
          String result = "OK";
          return result;
      }
  }
  </code></pre>
  
  <p>When I call this function from a Java agent, it appears to work without any issues. When I call it from a LotusScript agent via LS2J, it transfers the file but then it throws error 318 - LS2J Error: Threw java.lang.NullPointerException. The Java stack trace is:</p>
  
  <pre><code>java.lang.NullPointerException
      at lotus.notes.AgentSecurityManager.checkRelatedThreadGroup(Unknown Source)
      at lotus.notes.AgentSecurityManager.checkAccess(Unknown Source)
      at java.lang.Thread.checkAccess(Thread.java:378)
      at java.lang.Thread.interrupt(Thread.java:506)
      at com.jcraft.jsch.Session.disconnect(Session.java:1630)
      at SFTP.GetFile(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at lotus.domino.JavaConnectInvoker.invoke(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at lotus.domino.JavaConnectLoader.invoke(Unknown Source)
  </code></pre>
  
  <p>The issue seems to be with the session.disconnect() call. I've found others <a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;ved=0CFQQFjAA&amp;url=http://netbeans.org/bugzilla/show_bug.cgi?id=141609&amp;ei=jf3pT9q5MKro2QW-4aThCA&amp;usg=AFQjCNHDkqfP-uuTlmEZpJkQXJpTqtz-iQ&amp;sig2=-vojJp1370z87iW5oFYlRg" rel="nofollow noreferrer">with</a> <a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;ved=0CFUQFjAB&amp;url=http://sourceforge.net/tracker/?func=detail&amp;atid=509122&amp;aid=1701750&amp;group_id=64920&amp;ei=jf3pT9q5MKro2QW-4aThCA&amp;usg=AFQjCNHQy6pW8kk6IH35RIm1nl-JTTGRBw&amp;sig2=y1YzcURAiDWNKjYBJK8omw" rel="nofollow noreferrer">similar</a> <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=3&amp;ved=0CFYQFjAC&amp;url=https://bugs.eclipse.org/bugs/show_bug.cgi?format=multiple&amp;id=175328&amp;ei=jf3pT9q5MKro2QW-4aThCA&amp;usg=AFQjCNGDEaTWt1B-x19yjI8oXqJMcs2whg&amp;sig2=PmJAxCYAV4DyXdJxbK3HZg&amp;cad=rja" rel="nofollow noreferrer">issues</a> calling JSch from other applications, but if it's a JSch bug I would think the Java agent would throw the same exception. The stack trace makes it look like it's a Domino security issue, but I don't know what adjustment to make to allow this operation. The agent is already set to allow restricted operations, so that's not it. This <a href="http://www-10.lotus.com/ldd/46dom.nsf/869c7412fe5d56b7852569fa007826e3/02d5579edc50a6d88525687b004b21e8?OpenDocument" rel="nofollow noreferrer">forum post</a> has a similar stack trace and suggests that the issue may be caused by Domino owning cleanup rights on its thread group. </p>
  
  <p>Is there a security change I need to make on the Domino side? Can I remove the session.disconnect() without orphaning a zillion connections on the server?</p>