Author: markt Date: Wed Apr 5 15:13:24 2017 New Revision: 1790289 URL: http://svn.apache.org/viewvc?rev=1790289&view=rev Log: Partial fix for https://bz.apache.org/bugzilla/show_bug.cgi?id=47214 Replace explicitly referenced anonymous inner classes in CoyoteInputStream with named inner classes.
Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteInputStream.java tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteInputStream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteInputStream.java?rev=1790289&r1=1790288&r2=1790289&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/CoyoteInputStream.java (original) +++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteInputStream.java Wed Apr 5 15:13:24 2017 @@ -70,16 +70,7 @@ public class CoyoteInputStream extends S if (SecurityUtil.isPackageProtectionEnabled()) { try { - Integer result = AccessController - .doPrivileged(new PrivilegedExceptionAction<Integer>() { - - @Override - public Integer run() throws IOException { - Integer integer = Integer.valueOf(ib.readByte()); - return integer; - } - - }); + Integer result = AccessController.doPrivileged(new PrivilegedRead(ib)); return result.intValue(); } catch (PrivilegedActionException pae) { Exception e = pae.getException(); @@ -99,16 +90,7 @@ public class CoyoteInputStream extends S if (SecurityUtil.isPackageProtectionEnabled()) { try { - Integer result = AccessController - .doPrivileged(new PrivilegedExceptionAction<Integer>() { - - @Override - public Integer run() throws IOException { - Integer integer = Integer.valueOf(ib.available()); - return integer; - } - - }); + Integer result = AccessController.doPrivileged(new PrivilegedAvailable(ib)); return result.intValue(); } catch (PrivilegedActionException pae) { Exception e = pae.getException(); @@ -135,16 +117,8 @@ public class CoyoteInputStream extends S if (SecurityUtil.isPackageProtectionEnabled()) { try { - Integer result = AccessController - .doPrivileged(new PrivilegedExceptionAction<Integer>() { - - @Override - public Integer run() throws IOException { - Integer integer = Integer.valueOf(ib.read(b, off, len)); - return integer; - } - - }); + Integer result = AccessController.doPrivileged( + new PrivilegedReadArray(ib, b, off, len)); return result.intValue(); } catch (PrivilegedActionException pae) { Exception e = pae.getException(); @@ -176,16 +150,7 @@ public class CoyoteInputStream extends S if (SecurityUtil.isPackageProtectionEnabled()) { try { - Integer result = AccessController - .doPrivileged(new PrivilegedExceptionAction<Integer>() { - - @Override - public Integer run() throws IOException { - Integer integer = Integer.valueOf(ib.read(b)); - return integer; - } - - }); + Integer result = AccessController.doPrivileged(new PrivilegedReadBuffer(ib, b)); return result.intValue(); } catch (PrivilegedActionException pae) { Exception e = pae.getException(); @@ -211,15 +176,7 @@ public class CoyoteInputStream extends S if (SecurityUtil.isPackageProtectionEnabled()) { try { - AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() { - - @Override - public Void run() throws IOException { - ib.close(); - return null; - } - - }); + AccessController.doPrivileged(new PrivilegedClose(ib)); } catch (PrivilegedActionException pae) { Exception e = pae.getException(); if (e instanceof IOException) { @@ -256,4 +213,91 @@ public class CoyoteInputStream extends S throw new IllegalStateException(sm.getString("coyoteInputStream.nbNotready")); } } + + + private static class PrivilegedAvailable implements PrivilegedExceptionAction<Integer> { + + private final InputBuffer inputBuffer; + + public PrivilegedAvailable(InputBuffer inputBuffer) { + this.inputBuffer = inputBuffer; + } + + @Override + public Integer run() throws IOException { + return Integer.valueOf(inputBuffer.available()); + } + } + + + private static class PrivilegedClose implements PrivilegedExceptionAction<Void> { + + private final InputBuffer inputBuffer; + + public PrivilegedClose(InputBuffer inputBuffer) { + this.inputBuffer = inputBuffer; + } + + @Override + public Void run() throws IOException { + inputBuffer.close(); + return null; + } + } + + + private static class PrivilegedRead implements PrivilegedExceptionAction<Integer> { + + private final InputBuffer inputBuffer; + + public PrivilegedRead(InputBuffer inputBuffer) { + this.inputBuffer = inputBuffer; + } + + @Override + public Integer run() throws IOException { + Integer integer = Integer.valueOf(inputBuffer.readByte()); + return integer; + } + } + + + private static class PrivilegedReadArray implements PrivilegedExceptionAction<Integer> { + + private final InputBuffer inputBuffer; + private final byte[] buf; + private final int off; + private final int len; + + public PrivilegedReadArray(InputBuffer inputBuffer, byte[] buf, int off, int len) { + this.inputBuffer = inputBuffer; + this.buf = buf; + this.off = off; + this.len = len; + } + + @Override + public Integer run() throws IOException { + Integer integer = Integer.valueOf(inputBuffer.read(buf, off, len)); + return integer; + } + } + + + private static class PrivilegedReadBuffer implements PrivilegedExceptionAction<Integer> { + + private final InputBuffer inputBuffer; + private final ByteBuffer bb; + + public PrivilegedReadBuffer(InputBuffer inputBuffer, ByteBuffer bb) { + this.inputBuffer = inputBuffer; + this.bb = bb; + } + + @Override + public Integer run() throws IOException { + Integer integer = Integer.valueOf(inputBuffer.read(bb)); + return integer; + } + } } Modified: tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java?rev=1790289&r1=1790288&r2=1790289&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java (original) +++ tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java Wed Apr 5 15:13:24 2017 @@ -239,19 +239,19 @@ public final class SecurityClassLoad { "OutputBuffer$PrivilegedGetCharset"); loader.loadClass (basePackage + - "CoyoteInputStream$1"); + "CoyoteInputStream$PrivilegedAvailable"); loader.loadClass (basePackage + - "CoyoteInputStream$2"); + "CoyoteInputStream$PrivilegedClose"); loader.loadClass (basePackage + - "CoyoteInputStream$3"); + "CoyoteInputStream$PrivilegedRead"); loader.loadClass (basePackage + - "CoyoteInputStream$4"); + "CoyoteInputStream$PrivilegedReadArray"); loader.loadClass (basePackage + - "CoyoteInputStream$5"); + "CoyoteInputStream$PrivilegedReadBuffer"); loader.loadClass (basePackage + "InputBuffer$1"); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org