Skip to content

Commit

Permalink
Fix new Java 21 compiler warning: `possible 'this' escape before subc…
Browse files Browse the repository at this point in the history
…lass is fully initialized`.
  • Loading branch information
norrisjeremy committed Jul 16, 2023
1 parent 194b65f commit ae1e4f6
Show file tree
Hide file tree
Showing 25 changed files with 261 additions and 231 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* [0.2.10](https://github.com/mwiede/jsch/releases/tag/jsch-0.2.10)
* Fix new Java 21 compiler warning: `possible 'this' escape before subclass is fully initialized`.
* [0.2.9](https://github.com/mwiede/jsch/releases/tag/jsch-0.2.9)
* [#293](https://github.com/mwiede/jsch/issues/293) allow UserAuthNone to be extended.
* Make JGSS module optional.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jcraft/jsch/ChannelAgentForwarding.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class ChannelAgentForwarding extends Channel {
ChannelAgentForwarding() {
super();

setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;

type = Util.str2byte("auth-agent@openssh.com");
rbuf = new Buffer();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jcraft/jsch/ChannelDirectStreamLocal.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class ChannelDirectStreamLocal extends ChannelDirectTCPIP {
ChannelDirectStreamLocal() {
super();
type = _type;
setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jcraft/jsch/ChannelDirectTCPIP.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public class ChannelDirectTCPIP extends Channel {
ChannelDirectTCPIP() {
super();
type = _type;
setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jcraft/jsch/ChannelForwardedTCPIP.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public class ChannelForwardedTCPIP extends Channel {

ChannelForwardedTCPIP() {
super();
setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;
io = new IO();
connected = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jcraft/jsch/ChannelSftp.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ public int getBulkRequests() {

public ChannelSftp() {
super();
setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jcraft/jsch/ChannelX11.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ static void removeFakedCookie(Session session) {
ChannelX11() {
super();

setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;

type = Util.str2byte("x11");

Expand Down
19 changes: 9 additions & 10 deletions src/main/java/com/jcraft/jsch/IdentityFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,23 @@
import java.io.*;

class IdentityFile implements Identity {
private JSch jsch;
private KeyPair kpair;
private String identity;

static IdentityFile newInstance(String prvfile, String pubfile, JSch jsch) throws JSchException {
KeyPair kpair = KeyPair.load(jsch, prvfile, pubfile);
return new IdentityFile(jsch, prvfile, kpair);
static IdentityFile newInstance(String prvfile, String pubfile, JSch.InstanceLogger instLogger)
throws JSchException {
KeyPair kpair = KeyPair.load(instLogger, prvfile, pubfile);
return new IdentityFile(prvfile, kpair);
}

static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey, JSch jsch)
throws JSchException {
static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey,
JSch.InstanceLogger instLogger) throws JSchException {

KeyPair kpair = KeyPair.load(jsch, prvkey, pubkey);
return new IdentityFile(jsch, name, kpair);
KeyPair kpair = KeyPair.load(instLogger, prvkey, pubkey);
return new IdentityFile(name, kpair);
}

private IdentityFile(JSch jsch, String name, KeyPair kpair) throws JSchException {
this.jsch = jsch;
private IdentityFile(String name, KeyPair kpair) throws JSchException {
this.identity = name;
this.kpair = kpair;
}
Expand Down
35 changes: 25 additions & 10 deletions src/main/java/com/jcraft/jsch/JSch.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,11 @@ public class JSch {
config.put("ClearAllForwardings", "no");
}

final InstanceLogger instLogger = new InstanceLogger();

private Vector<Session> sessionPool = new Vector<>();

private IdentityRepository defaultIdentityRepository = new LocalIdentityRepository(this);
private IdentityRepository defaultIdentityRepository = new LocalIdentityRepository(instLogger);

private IdentityRepository identityRepository = defaultIdentityRepository;

Expand Down Expand Up @@ -291,7 +293,6 @@ public boolean isEnabled(int level) {
public void log(int level, String message) {}
};
static Logger logger = DEVNULL;
private Logger instLogger;

public JSch() {}

Expand Down Expand Up @@ -480,7 +481,7 @@ public void addIdentity(String prvkey, String passphrase) throws JSchException {
* @see #addIdentity(String prvkey, String pubkey, byte[] passphrase)
*/
public void addIdentity(String prvkey, byte[] passphrase) throws JSchException {
Identity identity = IdentityFile.newInstance(prvkey, null, this);
Identity identity = IdentityFile.newInstance(prvkey, null, instLogger);
addIdentity(identity, passphrase);
}

Expand All @@ -495,7 +496,7 @@ public void addIdentity(String prvkey, byte[] passphrase) throws JSchException {
* @throws JSchException if <code>passphrase</code> is not right.
*/
public void addIdentity(String prvkey, String pubkey, byte[] passphrase) throws JSchException {
Identity identity = IdentityFile.newInstance(prvkey, pubkey, this);
Identity identity = IdentityFile.newInstance(prvkey, pubkey, instLogger);
addIdentity(identity, passphrase);
}

Expand All @@ -511,7 +512,7 @@ public void addIdentity(String prvkey, String pubkey, byte[] passphrase) throws
*/
public void addIdentity(String name, byte[] prvkey, byte[] pubkey, byte[] passphrase)
throws JSchException {
Identity identity = IdentityFile.newInstance(name, prvkey, pubkey, this);
Identity identity = IdentityFile.newInstance(name, prvkey, pubkey, instLogger);
addIdentity(identity, passphrase);
}

Expand Down Expand Up @@ -669,10 +670,7 @@ public static void setLogger(Logger logger) {
* statically set logger is returned.
*/
public Logger getInstanceLogger() {
if (this.instLogger == null) {
return logger;
}
return instLogger;
return instLogger.getLogger();
}

/**
Expand All @@ -682,7 +680,7 @@ public Logger getInstanceLogger() {
* used
*/
public void setInstanceLogger(Logger logger) {
this.instLogger = logger;
instLogger.setLogger(logger);
}

/**
Expand All @@ -694,4 +692,21 @@ public void setInstanceLogger(Logger logger) {
public static Logger getLogger() {
return logger;
}

static class InstanceLogger {
private Logger logger;

private InstanceLogger() {}

Logger getLogger() {
if (logger == null) {
return JSch.logger;
}
return logger;
}

void setLogger(Logger logger) {
this.logger = logger;
}
}
}
Loading

0 comments on commit ae1e4f6

Please sign in to comment.