Source:
<code>public Channel connect() throws IOException, InterruptedException { try { out.println(JnlpProtocol3.NEGOTIATE_LINE); request.load(new ByteArrayInputStream(in.readUTF().getBytes(Charset.forName("UTF-8")))); nodeName = request.getProperty(JnlpProtocol3.SLAVE_NAME_KEY); this.handshakeCiphers = HandshakeCiphers.create(nodeName, getNodeSecret(nodeName)); authenticateToSlave(); if (getRequestProperty(JnlpProtocol3.COOKIE_KEY) != null) { cookie = handshakeCiphers.decrypt(getRequestProperty(JnlpProtocol3.COOKIE_KEY)); } validateSlave(); } catch (Failure f) { error(f.getMessage()); return null; } out.println(JnlpProtocol.GREETING_SUCCESS); String newCookie = null; String encryptedCookie = null; for (int loopCount = 0; loopCount < 110; loopCount++) { if (loopCount >= 100) { throw new IOException("JENKINS-37140 got really unlucky with the random number generator"); } newCookie = generateCookie(); encryptedCookie = handshakeCiphers.encrypt(newCookie); if (encryptedCookie.indexOf('\n') == -1) { break; } } out.println(encryptedCookie); String aesKeyString = handshakeCiphers.decrypt(in.readUTF()); String specKeyString = handshakeCiphers.decrypt(in.readUTF()); ChannelCiphers channelCiphers = ChannelCiphers.create( Jnlp3Util.keyFromString(aesKeyString), Jnlp3Util.keyFromString(specKeyString)); CipherInputStream in = null; CipherOutputStream out = null; final Channel channel; try { in = new CipherInputStream(SocketChannelStream.in(socket), channelCiphers.getDecryptCipher()); out = new CipherOutputStream(SocketChannelStream.out(socket), channelCiphers.getEncryptCipher()); channel = createChannelBuilder(nodeName).build(in, out); } catch (Exception ex) { EngineUtil.closeAndLogFailures(in, LOGGER, "CipherInputStream", socket.toString()); EngineUtil.closeAndLogFailures(out, LOGGER, "CipherOutputStream", socket.toString()); if (ex instanceof RuntimeException) { <START> throw (IOException) ex; <END> } else { throw new IOException("Unexpected runtime exception during creation of the channel", ex); } } channel.setProperty(COOKIE_NAME, newCookie); return channel; }</code><technical_language>cast unsafe</technical_language>

Target:
public Channel connect() throws IOException, InterruptedException { try { out.println(JnlpProtocol3.NEGOTIATE_LINE); request.load(new ByteArrayInputStream(in.readUTF().getBytes(Charset.forName("UTF-8")))); nodeName = request.getProperty(JnlpProtocol3.SLAVE_NAME_KEY); this.handshakeCiphers = HandshakeCiphers.create(nodeName, getNodeSecret(nodeName)); authenticateToSlave(); if (getRequestProperty(JnlpProtocol3.COOKIE_KEY) != null) { cookie = handshakeCiphers.decrypt(getRequestProperty(JnlpProtocol3.COOKIE_KEY)); } validateSlave(); } catch (Failure f) { error(f.getMessage()); return null; } out.println(JnlpProtocol.GREETING_SUCCESS); String newCookie = null; String encryptedCookie = null; for (int loopCount = 0; loopCount < 110; loopCount++) { if (loopCount >= 100) { throw new IOException("JENKINS-37140 got really unlucky with the random number generator"); } newCookie = generateCookie(); encryptedCookie = handshakeCiphers.encrypt(newCookie); if (encryptedCookie.indexOf('\n') == -1) { break; } } out.println(encryptedCookie); String aesKeyString = handshakeCiphers.decrypt(in.readUTF()); String specKeyString = handshakeCiphers.decrypt(in.readUTF()); ChannelCiphers channelCiphers = ChannelCiphers.create( Jnlp3Util.keyFromString(aesKeyString), Jnlp3Util.keyFromString(specKeyString)); CipherInputStream in = null; CipherOutputStream out = null; final Channel channel; try { in = new CipherInputStream(SocketChannelStream.in(socket), channelCiphers.getDecryptCipher()); out = new CipherOutputStream(SocketChannelStream.out(socket), channelCiphers.getEncryptCipher()); channel = createChannelBuilder(nodeName).build(in, out); } catch (Exception ex) { EngineUtil.closeAndLogFailures(in, LOGGER, "CipherInputStream", socket.toString()); EngineUtil.closeAndLogFailures(out, LOGGER, "CipherOutputStream", socket.toString()); if (ex instanceof IOException) { throw (IOException) ex; } else { throw new IOException("Unexpected runtime exception during creation of the channel", ex); } } channel.setProperty(COOKIE_NAME, newCookie); return channel; }