-
Notifications
You must be signed in to change notification settings - Fork 144
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
Replace old Hashtable with modern data structures. #624
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,8 @@ | |
|
||
import java.io.IOException; | ||
import java.net.Socket; | ||
import java.util.Hashtable; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
class ChannelX11 extends Channel { | ||
|
||
|
@@ -45,8 +46,8 @@ class ChannelX11 extends Channel { | |
static byte[] cookie = null; | ||
private static byte[] cookie_hex = null; | ||
|
||
private static Hashtable<Session, byte[]> faked_cookie_pool = new Hashtable<>(); | ||
private static Hashtable<Session, byte[]> faked_cookie_hex_pool = new Hashtable<>(); | ||
private static final Map<Session, byte[]> faked_cookie_pool = new ConcurrentHashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just keep faked_cookie_pool a HashMap and maintain the |
||
private static final Map<Session, byte[]> faked_cookie_hex_pool = new ConcurrentHashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there is any value in using a ConcurrentHashMap instead of a regular HashMap since all accesses to the faked_cookie_hex_pool are synchronized on faked_cookie_hex_pool anyway. |
||
|
||
private static byte[] table = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, | ||
0x62, 0x63, 0x64, 0x65, 0x66}; | ||
|
@@ -219,11 +220,8 @@ void write(byte[] foo, int s, int l) throws IOException { | |
|
||
byte[] bar = new byte[dlen]; | ||
System.arraycopy(foo, s + 12 + plen + ((-plen) & 3), bar, 0, dlen); | ||
byte[] faked_cookie = null; | ||
|
||
synchronized (faked_cookie_pool) { | ||
faked_cookie = faked_cookie_pool.get(_session); | ||
} | ||
byte[] faked_cookie = faked_cookie_pool.get(_session); | ||
|
||
/* | ||
* System.err.print("faked_cookie: "); for(int i=0; i<faked_cookie.length; i++){ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,15 +27,15 @@ | |
package com.jcraft.jsch; | ||
|
||
import java.io.InputStream; | ||
import java.util.Enumeration; | ||
import java.util.Hashtable; | ||
import java.util.Map; | ||
import java.util.Vector; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class JSch { | ||
/** The version number. */ | ||
public static final String VERSION = Version.getVersion(); | ||
|
||
static Hashtable<String, String> config = new Hashtable<>(); | ||
static Map<String, String> config = new ConcurrentHashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there is any value in using a |
||
|
||
static { | ||
config.put("kex", Util.getSystemProperty("jsch.kex", | ||
|
@@ -608,14 +608,10 @@ public static String getConfig(String key) { | |
* | ||
* @param newconf configurations | ||
*/ | ||
public static void setConfig(Hashtable<String, String> newconf) { | ||
public static void setConfig(Map<String, String> newconf) { | ||
synchronized (config) { | ||
for (Enumeration<String> e = newconf.keys(); e.hasMoreElements();) { | ||
String newkey = e.nextElement(); | ||
String key = | ||
(newkey.equals("PubkeyAcceptedKeyTypes") ? "PubkeyAcceptedAlgorithms" : newkey); | ||
config.put(key, newconf.get(newkey)); | ||
} | ||
newconf.forEach((key, value) -> config | ||
.put(key.equals("PubkeyAcceptedKeyTypes") ? "PubkeyAcceptedAlgorithms" : key, value)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather just see a traditional for loop over an |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertSame; | ||
|
||
import java.util.Hashtable; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fairly certain this doesn't meet Google Java style that we utilize. |
||
|
||
class JSchTest { | ||
|
||
@BeforeEach | ||
|
@@ -29,8 +31,8 @@ void setPubkeyAcceptedKeyTypes() throws JSchException { | |
} | ||
|
||
@Test | ||
void setPubkeyAcceptedKeyTypesHashtable() throws JSchException { | ||
Hashtable<String, String> newconf = new Hashtable<>(); | ||
void setPubkeyAcceptedKeyTypesHashtable() { | ||
Map<String, String> newconf = new HashMap<>(); | ||
newconf.put("PubkeyAcceptedKeyTypes", "JSchTest333"); | ||
JSch.setConfig(newconf); | ||
assertEquals("JSchTest333", JSch.getConfig("PubkeyAcceptedKeyTypes")); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is any value in using a ConcurrentHashMap instead of a regular HashMap since all accesses to the env are synchronized on env anyway.