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

Cannot invoke "com.jcraft.jsch.Cipher.isCBC()" because "cipher" is null #760

Open
hons82 opened this issue Jan 29, 2025 · 0 comments
Open

Comments

@hons82
Copy link

hons82 commented Jan 29, 2025

Currently I'm not able to reproduce this issue, but we got the following stacktrace in our logs sometimes

Cannot invoke "com.jcraft.jsch.Cipher.isCBC()" because "cipher" is null
	java.lang.NullPointerException: Cannot invoke "com.jcraft.jsch.Cipher.isCBC()" because "cipher" is null
		at com.jcraft.jsch.Session.start_discard(Session.java:1420)
		at com.jcraft.jsch.Session.read(Session.java:1240)
		at com.jcraft.jsch.Session.connect(Session.java:326)

The connect method is called by our code which is more or less this:

 public boolean isConnected() {
  return session != null && session.isConnected();
 }

 public synchronized boolean connect(int port) {
  try {
   if (!isConnected()) {
    JSch jsch = new JSch();
    KeyPair kp = getTunnelKeyPair();
    if (kp != null) {
     jsch.addIdentity(username, toByteArray(kp.getPrivate()), null, null);
    }
    session = jsch.getSession(username, "localhost", port);
    session.setServerAliveInterval(45000);
    session.setConfig("StrictHostKeyChecking", "no");
    session.connect(CONNECTION_TIMEOUT);
   }
  }
  catch (JSchException | IOException e) {
   LOGGER.log(Debug.INFO, "SSH connect", e.getMessage());
   disconnect();
  }
  return isConnected();
 }

 public synchronized void disconnect() {
  if (session != null)
   session.disconnect();
 }
 

Is there a way that I can check if this chiper exists prior to call connect, to avoid running into this Nullpointer?

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

No branches or pull requests

1 participant