Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.2.X' into 2.2.X
Browse files Browse the repository at this point in the history
  • Loading branch information
elecharny committed Aug 23, 2023
2 parents c723045 + 26f6f99 commit 3e638d1
Show file tree
Hide file tree
Showing 75 changed files with 151 additions and 143 deletions.
2 changes: 1 addition & 1 deletion mina-core/src/main/java/org/apache/mina/core/IoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static boolean awaitUninterruptibly(Iterable<? extends IoFuture> futures,
try {
return await0(futures, timeoutMillis, false);
} catch (InterruptedException e) {
throw new InternalError();
throw new IllegalStateException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ public IoBuffer putString(CharSequence val, CharsetEncoder encoder) throws Chara
expandedState++;
break;
default:
throw new RuntimeException(
throw new IllegalArgumentException(
"Expanded by " + (int) Math.ceil(in.remaining() * encoder.maxBytesPerChar())
+ " but that wasn't enough for '" + val + "'");
}
Expand Down Expand Up @@ -2106,7 +2106,7 @@ public IoBuffer putPrefixedString(CharSequence val, int prefixLength, int paddin
expandedState++;
break;
default:
throw new RuntimeException(
throw new IllegalArgumentException(
"Expanded by " + (int) Math.ceil(in.remaining() * encoder.maxBytesPerChar())
+ " but that wasn't enough for '" + val + "'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ Map<Integer, Queue<CachedBuffer>> newPoolMap() {
Map<Integer, Queue<CachedBuffer>> poolMap = new HashMap<>();

for (int i = 0; i < 31; i++) {
poolMap.put(1 << i, new ConcurrentLinkedQueue<CachedBuffer>());
poolMap.put(1 << i, new ConcurrentLinkedQueue<>());
}

poolMap.put(0, new ConcurrentLinkedQueue<CachedBuffer>());
poolMap.put(Integer.MAX_VALUE, new ConcurrentLinkedQueue<CachedBuffer>());
poolMap.put(0, new ConcurrentLinkedQueue<>());
poolMap.put(Integer.MAX_VALUE, new ConcurrentLinkedQueue<>());

return poolMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
try {
return await0(unit.toMillis(timeout), false);
} catch (InterruptedException e) {
throw new InternalError();
throw new IllegalStateException();
}
}

Expand All @@ -173,7 +173,7 @@ public boolean awaitUninterruptibly(long timeoutMillis) {
try {
return await0(timeoutMillis, false);
} catch (InterruptedException e) {
throw new InternalError();
throw new IllegalStateException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public abstract class AbstractPollingIoAcceptor<S extends AbstractIoSession, H>

private final Queue<AcceptorOperationFuture> cancelQueue = new ConcurrentLinkedQueue<>();

private final Map<SocketAddress, H> boundHandles = Collections.synchronizedMap(new HashMap<SocketAddress, H>());
private final Map<SocketAddress, H> boundHandles = Collections.synchronizedMap(new HashMap<>());

private final ServiceOperationFuture disposalFuture = new ServiceOperationFuture();

Expand Down Expand Up @@ -116,7 +116,7 @@ public abstract class AbstractPollingIoAcceptor<S extends AbstractIoSession, H>
* type.
*/
protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass) {
this(sessionConfig, null, new SimpleIoProcessorPool<S>(processorClass), true, null);
this(sessionConfig, null, new SimpleIoProcessorPool<>(processorClass), true, null);
}

/**
Expand All @@ -135,7 +135,7 @@ protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? exten
*/
protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass,
int processorCount) {
this(sessionConfig, null, new SimpleIoProcessorPool<S>(processorClass, processorCount), true, null);
this(sessionConfig, null, new SimpleIoProcessorPool<>(processorClass, processorCount), true, null);
}

/**
Expand All @@ -155,7 +155,7 @@ protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? exten
*/
protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass,
int processorCount, SelectorProvider selectorProvider ) {
this(sessionConfig, null, new SimpleIoProcessorPool<S>(processorClass, processorCount, selectorProvider), true, selectorProvider);
this(sessionConfig, null, new SimpleIoProcessorPool<>(processorClass, processorCount, selectorProvider), true, selectorProvider);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public abstract class AbstractPollingIoConnector<S extends AbstractIoSession, H>
* {@link IoSession} type.
*/
protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass) {
this(sessionConfig, null, new SimpleIoProcessorPool<S>(processorClass), true);
this(sessionConfig, null, new SimpleIoProcessorPool<>(processorClass), true);
}

/**
Expand All @@ -117,7 +117,7 @@ protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Class<? exte
*/
protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass,
int processorCount) {
this(sessionConfig, null, new SimpleIoProcessorPool<S>(processorClass, processorCount), true);
this(sessionConfig, null, new SimpleIoProcessorPool<>(processorClass, processorCount), true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public boolean isDisposing() {
setAttributeMap(factory.getAttributeMap(this));
setWriteRequestQueue(factory.getWriteRequestQueue(this));
} catch (Exception e) {
throw new InternalError();
throw new IllegalStateException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ private static List<WriteRequest> asRequestList(Collection<WriteRequest> request
}

// Create a list of requests removing duplicates.
Set<WriteRequest> newRequests = new MapBackedSet<>(new LinkedHashMap<WriteRequest, Boolean>());
Set<WriteRequest> newRequests = new MapBackedSet<>(new LinkedHashMap<>());

for (WriteRequest r : requests) {
newRequests.add(r.getOriginalRequest());
}

return Collections.unmodifiableList(new ArrayList<WriteRequest>(newRequests));
return Collections.unmodifiableList(new ArrayList<>(newRequests));
}

private static List<WriteRequest> asRequestList(WriteRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public BufferedWriteFilter(int bufferSize, LazyInitializedCacheMap<IoSession, Io
super();
this.bufferSize = bufferSize;
if (buffersMap == null) {
this.buffersMap = new LazyInitializedCacheMap<IoSession, IoBuffer>();
this.buffersMap = new LazyInitializedCacheMap<>();
} else {
this.buffersMap = buffersMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Excep
return finishDecode((firstByte << 24) | (secondByte << 16) | (thirdByte << 8) | in.getUnsigned(), out);

default:
throw new InternalError();
throw new IllegalStateException();
}

counter++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Excep
return finishDecode((short) ((highByte << 8) | in.getUnsigned()), out);

default:
throw new InternalError();
throw new IllegalStateException();
}

counter++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public OrderedThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long kee
// We have to initialize the pool with default values (0 and 1) in order to
// handle the exception in a better way. We can't add a try {} catch() {}
// around the super() call.
super(DEFAULT_INITIAL_THREAD_POOL_SIZE, 1, keepAliveTime, unit, new SynchronousQueue<Runnable>(),
super(DEFAULT_INITIAL_THREAD_POOL_SIZE, 1, keepAliveTime, unit, new SynchronousQueue<>(),
threadFactory, new AbortPolicy());

if (corePoolSize < DEFAULT_INITIAL_THREAD_POOL_SIZE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public PriorityThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long ke
// handle the exception in a better way. We can't add a try {} catch()
// {}
// around the super() call.
super(DEFAULT_INITIAL_THREAD_POOL_SIZE, 1, keepAliveTime, unit, new SynchronousQueue<Runnable>(), threadFactory,
super(DEFAULT_INITIAL_THREAD_POOL_SIZE, 1, keepAliveTime, unit, new SynchronousQueue<>(), threadFactory,
new AbortPolicy());

if (corePoolSize < DEFAULT_INITIAL_THREAD_POOL_SIZE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public UnorderedThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long k
*/
public UnorderedThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit,
ThreadFactory threadFactory, IoEventQueueHandler queueHandler) {
super(0, 1, keepAliveTime, unit, new LinkedBlockingQueue<Runnable>(), threadFactory, new AbortPolicy());
super(0, 1, keepAliveTime, unit, new LinkedBlockingQueue<>(), threadFactory, new AbortPolicy());

if (corePoolSize < 0) {
throw new IllegalArgumentException("corePoolSize: " + corePoolSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
public class BlacklistFilter extends IoFilterAdapter {
/** The list of blocked addresses */
private final List<Subnet> blacklist = new CopyOnWriteArrayList<Subnet>();
private final List<Subnet> blacklist = new CopyOnWriteArrayList<>();

/** A logger for this class */
private final static Logger LOGGER = LoggerFactory.getLogger(BlacklistFilter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public ConnectionThrottleFilter() {
*/
public ConnectionThrottleFilter(long allowedInterval) {
this.allowedInterval = allowedInterval;
clients = new ConcurrentHashMap<String, Long>();
clients = new ConcurrentHashMap<>();

// Create the cleanup thread
ExpiredSessionThread cleanupThread = new ExpiredSessionThread();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class SslFilter extends IoFilterAdapter {
* Task executor for processing handshakes
*/
static protected final Executor EXECUTOR = new ThreadPoolExecutor(2, 2, 100, TimeUnit.MILLISECONDS,
new LinkedBlockingDeque<Runnable>(), new BasicThreadFactory("ssl-exec", true));
new LinkedBlockingDeque<>(), new BasicThreadFactory("ssl-exec", true));

protected final SSLContext sslContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public void stopProfile(IoEventType type) {
* @return a Set containing all the profiled {@link IoEventType}
*/
public Set<IoEventType> getEventsToProfile() {
Set<IoEventType> set = new HashSet<IoEventType>();
Set<IoEventType> set = new HashSet<>();

if (profileMessageReceived) {
set.add(IoEventType.MESSAGE_RECEIVED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public synchronized IoHandlerCommand remove(String name) {
* @throws Exception If we faced some exception during the cleanup
*/
public synchronized void clear() throws Exception {
Iterator<String> it = new ArrayList<String>(name2entry.keySet()).iterator();
Iterator<String> it = new ArrayList<>(name2entry.keySet()).iterator();

while (it.hasNext()) {
remove(it.next());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected synchronized void flushPendingWriteRequests() throws Exception {
*/
public synchronized void enqueueWriteRequest(final NextFilter nextFilter, final WriteRequest writeRequest) {
if (writeRequestQueue == null) {
writeRequestQueue = new LinkedList<Event>();
writeRequestQueue = new LinkedList<>();
}

writeRequestQueue.offer(new Event(nextFilter, writeRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void doHandshake(final NextFilter nextFilter) throws ProxyAuthException {
// Compute request headers
HttpProxyRequest req = (HttpProxyRequest) getProxyIoSession().getRequest();
Map<String, List<String>> headers = req.getHeaders() != null ? req.getHeaders()
: new HashMap<String, List<String>>();
: new HashMap<>();

AbstractAuthLogicHandler.addKeepAliveHeaders(headers);
req.setHeaders(headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void doHandshake(final NextFilter nextFilter) throws ProxyAuthException {
// Send request
HttpProxyRequest req = (HttpProxyRequest) request;
Map<String, List<String>> headers = req.getHeaders() != null ? req.getHeaders()
: new HashMap<String, List<String>>();
: new HashMap<>();

String username = req.getProperties().get(HttpProxyConstants.USER_PROPERTY);
String password = req.getProperties().get(HttpProxyConstants.PWD_PROPERTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class DigestUtilities {
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class HttpDigestAuthLogicHandler extends AbstractAuthLogicHandler {
try {
rnd = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public void doHandshake(NextFilter nextFilter) throws ProxyAuthException {

HttpProxyRequest req = (HttpProxyRequest) request;
Map<String, List<String>> headers = req.getHeaders() != null ? req.getHeaders()
: new HashMap<String, List<String>>();
: new HashMap<>();

if (step > 0) {
if (LOGGER.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void doHandshake(NextFilter nextFilter) throws ProxyAuthException {

HttpProxyRequest req = (HttpProxyRequest) request;
Map<String, List<String>> headers = req.getHeaders() != null ? req.getHeaders()
: new HashMap<String, List<String>>();
: new HashMap<>();

String domain = req.getProperties().get(HttpProxyConstants.DOMAIN_PROPERTY);
String workstation = req.getProperties().get(HttpProxyConstants.WORKSTATION_PROPERTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
*/
package org.apache.mina.proxy.handlers.http.ntlm;

import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;

/**
Expand Down Expand Up @@ -179,9 +183,10 @@ public static byte[] getNTLM2SessionResponse(String password, byte[] challenge,
*
* @return The LM Hash of the given password, used in the calculation
* of the LM Response.
* @throws GeneralSecurityException if an encryption problem occurs.
*/
private static byte[] lmHash(String password) throws Exception {
byte[] oemPassword = password.toUpperCase().getBytes("US-ASCII");
private static byte[] lmHash(String password) throws GeneralSecurityException{
byte[] oemPassword = password.toUpperCase().getBytes(StandardCharsets.US_ASCII);
int length = Math.min(oemPassword.length, 14);
byte[] keyBytes = new byte[14];
System.arraycopy(oemPassword, 0, keyBytes, 0, length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.apache.mina.proxy.handlers.socks;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import org.apache.mina.core.buffer.IoBuffer;
Expand Down Expand Up @@ -72,8 +73,8 @@ public void doHandshake(final NextFilter nextFilter) {
protected void writeRequest(final NextFilter nextFilter, final SocksProxyRequest request) {
try {
boolean isV4ARequest = Arrays.equals(request.getIpAddress(), SocksProxyConstants.FAKE_IP);
byte[] userID = request.getUserName() != null ? request.getUserName().getBytes("ASCII") : null;
byte[] host = request.getHost() != null ? request.getHost().getBytes("ASCII") : null;
byte[] userID = request.getUserName() != null ? request.getUserName().getBytes(StandardCharsets.US_ASCII) : null;
byte[] host = request.getHost() != null ? request.getHost().getBytes(StandardCharsets.US_ASCII) : null;
int len = 9 + userID.length;

if (isV4ARequest) {
Expand Down
Loading

0 comments on commit 3e638d1

Please sign in to comment.