[tomcat] branch 8.5.x updated: Simplify code. Based on PR #651 by wonyongChoi05

2023-09-05 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
 new 840180fe73 Simplify code. Based on PR #651 by wonyongChoi05
840180fe73 is described below

commit 840180fe730dbaf4c98c9a81c30ee97d77260d32
Author: Mark Thomas 
AuthorDate: Tue Sep 5 11:22:49 2023 +0100

Simplify code. Based on PR #651 by wonyongChoi05
---
 java/org/apache/coyote/ajp/AjpProcessor.java | 20 +++-
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/java/org/apache/coyote/ajp/AjpProcessor.java 
b/java/org/apache/coyote/ajp/AjpProcessor.java
index bf2a570d76..2b14407e2c 100644
--- a/java/org/apache/coyote/ajp/AjpProcessor.java
+++ b/java/org/apache/coyote/ajp/AjpProcessor.java
@@ -26,8 +26,10 @@ import java.security.NoSuchProviderException;
 import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.regex.Pattern;
 
@@ -1249,10 +1251,10 @@ public class AjpProcessor extends AbstractProcessor {
 @Override
 protected final void populateSslRequestAttributes() {
 if (!certificates.isNull()) {
+List jsseCerts = new ArrayList<>();
 ByteChunk certData = certificates.getByteChunk();
-X509Certificate jsseCerts[] = null;
-ByteArrayInputStream bais = new 
ByteArrayInputStream(certData.getBytes(), certData.getStart(),
-certData.getLength());
+ByteArrayInputStream bais =
+new ByteArrayInputStream(certData.getBytes(), 
certData.getStart(), certData.getLength());
 // Fill the elements.
 try {
 CertificateFactory cf;
@@ -1264,21 +1266,13 @@ public class AjpProcessor extends AbstractProcessor {
 }
 while (bais.available() > 0) {
 X509Certificate cert = (X509Certificate) 
cf.generateCertificate(bais);
-if (jsseCerts == null) {
-jsseCerts = new X509Certificate[1];
-jsseCerts[0] = cert;
-} else {
-X509Certificate[] temp = new 
X509Certificate[jsseCerts.length + 1];
-System.arraycopy(jsseCerts, 0, temp, 0, 
jsseCerts.length);
-temp[jsseCerts.length] = cert;
-jsseCerts = temp;
-}
+jsseCerts.add(cert);
 }
 } catch (CertificateException | NoSuchProviderException e) {
 getLog().error(sm.getString("ajpprocessor.certs.fail"), e);
 return;
 }
-request.setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts);
+request.setAttribute(SSLSupport.CERTIFICATE_KEY, 
jsseCerts.toArray(new X509Certificate[0]));
 }
 }
 


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 8.5.x updated: Simplify code - no functional change

2021-07-27 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
 new 8972e7b  Simplify code - no functional change
8972e7b is described below

commit 8972e7b80186fc38a4f2bbcd97cc60e608bf1d06
Author: Mark Thomas 
AuthorDate: Tue Jul 27 21:53:08 2021 +0100

Simplify code - no functional change
---
 .../catalina/loader/WebappClassLoaderBase.java | 69 ++
 1 file changed, 31 insertions(+), 38 deletions(-)

diff --git a/java/org/apache/catalina/loader/WebappClassLoaderBase.java 
b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
index b73e992..e7a35db 100644
--- a/java/org/apache/catalina/loader/WebappClassLoaderBase.java
+++ b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
@@ -2436,49 +2436,42 @@ public abstract class WebappClassLoaderBase extends 
URLClassLoader
 }
 }
 
-// Looking up the package
-String packageName = null;
-int pos = name.lastIndexOf('.');
-if (pos != -1) {
-packageName = name.substring(0, pos);
-}
-
-Package pkg = null;
-
-if (packageName != null) {
-pkg = getPackage(packageName);
-// Define the package (if null)
-if (pkg == null) {
-try {
-if (manifest == null) {
-definePackage(packageName, null, null, null, null, 
null, null, null);
-} else {
-definePackage(packageName, manifest, codeBase);
+if (securityManager != null) {
+// Looking up the package
+int pos = name.lastIndexOf('.');
+if (pos != -1) {
+String packageName = name.substring(0, pos);
+Package pkg = getPackage(packageName);
+
+// Define the package (if null)
+if (pkg == null) {
+try {
+if (manifest == null) {
+definePackage(packageName, null, null, null, 
null, null, null, null);
+} else {
+definePackage(packageName, manifest, codeBase);
+}
+} catch (IllegalArgumentException e) {
+// Ignore: normal error due to dual definition of 
package
 }
-} catch (IllegalArgumentException e) {
-// Ignore: normal error due to dual definition of 
package
+pkg = getPackage(packageName);
 }
-pkg = getPackage(packageName);
-}
-}
-
-if (securityManager != null) {
 
-// Checking sealing
-if (pkg != null) {
-boolean sealCheck = true;
-if (pkg.isSealed()) {
-sealCheck = pkg.isSealed(codeBase);
-} else {
-sealCheck = (manifest == null) || 
!isPackageSealed(packageName, manifest);
-}
-if (!sealCheck) {
-throw new SecurityException
-("Sealing violation loading " + name + " : Package 
"
- + packageName + " is sealed.");
+// Checking sealing
+if (pkg != null) {
+boolean sealCheck = true;
+if (pkg.isSealed()) {
+sealCheck = pkg.isSealed(codeBase);
+} else {
+sealCheck = (manifest == null) || 
!isPackageSealed(packageName, manifest);
+}
+if (!sealCheck) {
+throw new SecurityException
+("Sealing violation loading " + name + " : 
Package "
+ + packageName + " is sealed.");
+}
 }
 }
-
 }
 
 try {

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 8.5.x updated: Simplify code

2019-03-15 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
 new 9e9f28e  Simplify code
9e9f28e is described below

commit 9e9f28efceee78dd928966a87d9aa73326d8fc3f
Author: Mark Thomas 
AuthorDate: Fri Mar 15 13:29:04 2019 +

Simplify code
---
 java/org/apache/tomcat/util/buf/B2CConverter.java | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/java/org/apache/tomcat/util/buf/B2CConverter.java 
b/java/org/apache/tomcat/util/buf/B2CConverter.java
index 2dd63c0..9d72234 100644
--- a/java/org/apache/tomcat/util/buf/B2CConverter.java
+++ b/java/org/apache/tomcat/util/buf/B2CConverter.java
@@ -37,11 +37,8 @@ public class B2CConverter {
 private static final StringManager sm =
 StringManager.getManager(Constants.Package);
 
-private static final CharsetCache charsetCache;
+private static final CharsetCache charsetCache = new CharsetCache();
 
-static {
-charsetCache = new CharsetCache();
-}
 
 // Protected so unit tests can use it
 protected static final int LEFTOVER_SIZE = 9;


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org