From d6336323fdce4e885ee4665838c12c79eaa7c5cb Mon Sep 17 00:00:00 2001 From: Chad Wilson <29788154+chadlwilson@users.noreply.github.com> Date: Wed, 23 Jul 2025 11:41:54 +0800 Subject: [PATCH 1/2] Tidy code for modern Java versions --- .../jruby/rack/DefaultErrorApplication.java | 19 +++----- .../jruby/rack/DefaultRackApplication.java | 7 +-- .../rack/DefaultRackApplicationFactory.java | 4 +- .../org/jruby/rack/DefaultRackConfig.java | 23 +++++----- .../org/jruby/rack/DefaultRackDispatcher.java | 2 +- .../rack/PoolingRackApplicationFactory.java | 28 +++++------- .../rack/RackApplicationFactoryDecorator.java | 2 +- .../java/org/jruby/rack/RackResponse.java | 2 +- .../org/jruby/rack/UnmappedRackFilter.java | 26 +++++------ src/main/java/org/jruby/rack/ext/Input.java | 9 +--- src/main/java/org/jruby/rack/ext/Logger.java | 12 +---- .../java/org/jruby/rack/ext/Response.java | 43 ++++++++---------- src/main/java/org/jruby/rack/ext/Servlet.java | 6 +-- .../jruby/rack/servlet/RequestCapture.java | 45 +++++++++---------- .../jruby/rack/servlet/ResponseCapture.java | 6 +-- .../rack/servlet/ServletRackEnvironment.java | 5 +-- .../org/jruby/rack/util/ExceptionUtils.java | 2 +- 17 files changed, 96 insertions(+), 145 deletions(-) diff --git a/src/main/java/org/jruby/rack/DefaultErrorApplication.java b/src/main/java/org/jruby/rack/DefaultErrorApplication.java index 777bf4ea8..1abd3ecbf 100644 --- a/src/main/java/org/jruby/rack/DefaultErrorApplication.java +++ b/src/main/java/org/jruby/rack/DefaultErrorApplication.java @@ -86,8 +86,7 @@ static Exception getException(RackEnvironment env) { private class Response implements RackResponse { private int status = 500; - @SuppressWarnings("rawtypes") - private Map headers = Collections.EMPTY_MAP; + private Map headers = Collections.emptyMap(); private String body; protected final RackEnvironment env; @@ -103,14 +102,13 @@ public void setStatus(int status) { this.status = status; } - @SuppressWarnings("rawtypes") - public Map getHeaders() { + public Map getHeaders() { return headers; } @SuppressWarnings("unused") - public void setHeaders(@SuppressWarnings("rawtypes") Map headers) { - this.headers = headers == null ? Collections.EMPTY_MAP : headers; + public void setHeaders(Map headers) { + this.headers = headers == null ? Collections.emptyMap() : headers; } public String getBody() { @@ -161,15 +159,12 @@ private void log(RackLogger.Level level, String message, Throwable e) { } - @SuppressWarnings("rawtypes") public static void defaultRespond(final RackResponse rackResponse, final RackResponseEnvironment responseEnv) throws IOException { responseEnv.setStatus( rackResponse.getStatus() ); - @SuppressWarnings("unchecked") - final Set headers = rackResponse.getHeaders().entrySet(); - for ( Iterator it = headers.iterator(); it.hasNext(); ) { - final Map.Entry entry = it.next(); - final String key = entry.getKey().toString(); + final Set> headers = rackResponse.getHeaders().entrySet(); + for (final Map.Entry entry : headers) { + final String key = entry.getKey(); final Object value = entry.getValue(); responseEnv.addHeader(key, value != null ? value.toString() : null); } diff --git a/src/main/java/org/jruby/rack/DefaultRackApplication.java b/src/main/java/org/jruby/rack/DefaultRackApplication.java index bbe049875..64fc25610 100644 --- a/src/main/java/org/jruby/rack/DefaultRackApplication.java +++ b/src/main/java/org/jruby/rack/DefaultRackApplication.java @@ -50,13 +50,8 @@ public RackResponse call(final RackEnvironment env) { final IRubyObject app = getApplication(); final Ruby runtime = getRuntime(); final IRubyObject servlet_env = JavaEmbedUtils.javaToRuby(runtime, env); - //try { // app.call(env) : final IRubyObject response = app.callMethod(runtime.getCurrentContext(), "call", servlet_env); - return (RackResponse) response.toJava(RackResponse.class); - //} - //catch (RuntimeException e) { - // throw ExceptionUtils.wrapException(runtime, e); - //} + return response.toJava(RackResponse.class); } @Override diff --git a/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java b/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java index 7b4887e35..c51dcabce 100644 --- a/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java +++ b/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java @@ -199,7 +199,7 @@ public IRubyObject createErrorApplicationObject(final Ruby runtime) { public RackApplication newErrorApplication() { Boolean error = rackContext.getConfig().getBooleanProperty("jruby.rack.error"); - if ( error != null && ! error.booleanValue() ) { // jruby.rack.error = false + if ( error != null && !error) { // jruby.rack.error = false return new DefaultErrorApplication(rackContext); } try { @@ -557,7 +557,7 @@ private void configureDefaults() { if (iniSize == null) iniSize = RewindableInputStream.INI_BUFFER_SIZE; Integer maxSize = config.getMaximumMemoryBufferSize(); if (maxSize == null) maxSize = RewindableInputStream.MAX_BUFFER_SIZE; - if (iniSize.intValue() > maxSize.intValue()) iniSize = maxSize; + if (iniSize > maxSize) iniSize = maxSize; RewindableInputStream.setDefaultInitialBufferSize(iniSize); RewindableInputStream.setDefaultMaximumBufferSize(maxSize); diff --git a/src/main/java/org/jruby/rack/DefaultRackConfig.java b/src/main/java/org/jruby/rack/DefaultRackConfig.java index 5667a7851..874be72a1 100644 --- a/src/main/java/org/jruby/rack/DefaultRackConfig.java +++ b/src/main/java/org/jruby/rack/DefaultRackConfig.java @@ -123,7 +123,7 @@ public boolean isSerialInitialization() { } } } - return serial.booleanValue(); + return serial; } @Override @@ -156,10 +156,7 @@ protected RackLogger createLogger(final String loggerClass) { Constructor ctor = klass.getConstructor(String.class); return (RackLogger) ctor.newInstance( getLoggerName() ); } - catch (NoSuchMethodException retry) { - return newLoggerInstance(klass, retry); - } - catch (IllegalAccessException retry) { + catch (NoSuchMethodException | IllegalAccessException retry) { return newLoggerInstance(klass, retry); } catch (InstantiationException e) { @@ -268,7 +265,7 @@ static boolean isIgnoreRUBYOPT(RackConfig config) { // RUBYOPT ignored if jruby.runtime.env.rubyopt = false Boolean rubyopt = config.getBooleanProperty("jruby.runtime.env.rubyopt"); if ( rubyopt == null ) return ! config.isIgnoreEnvironment(); - return rubyopt != null && ! rubyopt.booleanValue(); + return rubyopt != null && !rubyopt; } @Override @@ -282,11 +279,11 @@ public boolean isThrowInitException() { static boolean isThrowInitException(RackConfig config) { Boolean error = config.getBooleanProperty("jruby.rack.error"); - if ( error != null && error.booleanValue() ) { + if ( error != null && error) { return false; // jruby.rack.error = true } error = config.getBooleanProperty(RackEnvironment.EXCEPTION); - if ( error != null && error.booleanValue() ) { + if ( error != null && error) { return false; // jruby.rack.exception = true } return true; @@ -335,7 +332,7 @@ private Integer getPositiveInteger(String key) { if (value == null) return null; try { int i = Integer.parseInt(value); - if (i > 0) return Integer.valueOf(i); + if (i > 0) return i; } catch (Exception e) { /* ignored */ } return null; } @@ -367,12 +364,12 @@ public static Number toNumber(String value, Number defaultValue) { } if ( number == ((int) number) ) if ( number > Integer.MAX_VALUE ) { - return Long.valueOf((long) number); + return (long) number; } else { - return Integer.valueOf((int) number); + return (int) number; } - return Float.valueOf(number); + return number; } catch (Exception e) { /* ignored */ } return defaultValue; @@ -386,7 +383,7 @@ private Map toStringMap(final String env) { GEM_HOME=/opt/local/rvm/gems/jruby-1.6.8@jruby-rack */ LineNumberReader reader = new LineNumberReader(new StringReader(env.trim())); - Map map = new LinkedHashMap(); String line; + Map map = new LinkedHashMap<>(); String line; try { while ( (line = reader.readLine()) != null ) { final String[] entries = line.split(","); diff --git a/src/main/java/org/jruby/rack/DefaultRackDispatcher.java b/src/main/java/org/jruby/rack/DefaultRackDispatcher.java index 611f672c0..5205891e1 100644 --- a/src/main/java/org/jruby/rack/DefaultRackDispatcher.java +++ b/src/main/java/org/jruby/rack/DefaultRackDispatcher.java @@ -57,7 +57,7 @@ protected void afterException( // TODO seems redundant maybe we should let the container decide ?! context.log(ERROR, "error app failed to handle exception: " + e, re); Integer errorCode = getErrorApplicationFailureStatusCode(); - if ( errorCode != null && errorCode.intValue() > 0 ) { + if ( errorCode != null && errorCode > 0 ) { response.sendError(errorCode); } else { diff --git a/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java b/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java index 4c6f5fb0a..e4c777fb6 100644 --- a/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java +++ b/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java @@ -49,7 +49,7 @@ public class PoolingRackApplicationFactory extends RackApplicationFactoryDecorat // 10 seconds seems still too much for a default, has been 30 previously : private static final float ACQUIRE_DEFAULT = 10.0f; - protected final Queue applicationPool = new LinkedList(); + protected final Queue applicationPool = new LinkedList<>(); private Integer initialSize, maximumSize; private final AtomicInteger initedApplications = new AtomicInteger(0); @@ -294,19 +294,15 @@ protected void launchInitialization(final Queue apps) { if ( initThreads == null ) initThreads = 4; // quad-core baby for (int i = 0; i < initThreads; i++) { - new Thread(new Runnable() { - @Override - public void run() { - while (true) { - final RackApplication app; - synchronized (apps) { - if ( apps.isEmpty() ) break; - app = apps.remove(); - } - if ( ! initAndPutApplicationToPool(app) ) break; + new Thread(() -> { + while (true) { + final RackApplication app; + synchronized (apps) { + if ( apps.isEmpty() ) break; + app = apps.remove(); } + if ( ! initAndPutApplicationToPool(app) ) break; } - }, "JRuby-Rack-App-Init-" + i).start(); } } @@ -395,14 +391,14 @@ private int getInitialPoolSizeWait() { if ( waitNum != null ) { int wait = waitNum.intValue(); if (maximumSize != null && wait > maximumSize) { - wait = maximumSize.intValue(); + wait = maximumSize; } return wait; } // otherwise we assume it to be a boolean true/false flag : Boolean waitFlag = getConfig().getBooleanProperty("jruby.runtime.init.wait"); if ( waitFlag == null ) waitFlag = Boolean.TRUE; - return waitFlag ? ( initialSize == null ? 1 : initialSize.intValue() ) : 0; + return waitFlag ? ( initialSize == null ? 1 : initialSize) : 0; // NOTE: this slightly changes the behavior in 1.1.8, in previous // versions the initialization only waited for 1 application instance // to be available in the pool - here by default we wait till initial @@ -411,14 +407,14 @@ private int getInitialPoolSizeWait() { @Override public Collection getManagedApplications() { - int initSize = initialSize != null ? initialSize.intValue() : -1; + int initSize = initialSize != null ? initialSize : -1; synchronized (applicationPool) { if ( applicationPool.isEmpty() ) { if ( initSize > 0 ) return null; // ~ init error return Collections.emptySet(); } Collection snapshot = - new ArrayList(applicationPool); + new ArrayList<>(applicationPool); return Collections.unmodifiableCollection(snapshot); } } diff --git a/src/main/java/org/jruby/rack/RackApplicationFactoryDecorator.java b/src/main/java/org/jruby/rack/RackApplicationFactoryDecorator.java index 3ee4d757b..5111a2e48 100644 --- a/src/main/java/org/jruby/rack/RackApplicationFactoryDecorator.java +++ b/src/main/java/org/jruby/rack/RackApplicationFactoryDecorator.java @@ -204,7 +204,7 @@ private RackContext getContextBang() throws IllegalStateException { public static Collection getManagedRuntimes(RackApplicationFactoryDecorator factory) { final Collection apps = factory.getManagedApplications(); if ( apps == null ) return null; - final Set runtimes = new LinkedHashSet(apps.size()); + final Set runtimes = new LinkedHashSet<>(apps.size()); for ( RackApplication app : apps ) { runtimes.add( app.getRuntime() ); } diff --git a/src/main/java/org/jruby/rack/RackResponse.java b/src/main/java/org/jruby/rack/RackResponse.java index e001bdab2..1eace39c1 100644 --- a/src/main/java/org/jruby/rack/RackResponse.java +++ b/src/main/java/org/jruby/rack/RackResponse.java @@ -32,7 +32,7 @@ public interface RackResponse { /** * @return the response headers (string key names) */ - Map getHeaders() ; + Map getHeaders() ; /** * Note: Normally, this method won't be used at all as we stream the diff --git a/src/main/java/org/jruby/rack/UnmappedRackFilter.java b/src/main/java/org/jruby/rack/UnmappedRackFilter.java index 96044f18c..21b446de6 100644 --- a/src/main/java/org/jruby/rack/UnmappedRackFilter.java +++ b/src/main/java/org/jruby/rack/UnmappedRackFilter.java @@ -8,10 +8,8 @@ import java.io.FileNotFoundException; import java.io.IOException; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; @@ -46,7 +44,7 @@ public class UnmappedRackFilter extends AbstractFilter { private static final Collection RESPONSE_NOT_HANDLED_STATUSES; static { - final HashSet statuses = new HashSet(8, 1); + final Set statuses = new HashSet<>(8, 1); statuses.add( 404 ); // 403 due containers not supporting PUT/DELETE correctly (Tomcat 6) statuses.add( 403 ); @@ -89,14 +87,11 @@ public void init(FilterConfig config) throws ServletException { // ResponseCapture.notHandledStatuses e.g. "403,404,500" value = config.getInitParameter("responseNotHandledStatuses"); if ( value != null ) { - final Set statuses = new HashSet(); - for ( String status : value.split(",") ) { - status = status.trim(); - if ( status.length() > 0 ) { - statuses.add( Integer.parseInt(status) ); - } - } - responseNotHandledStatuses = statuses; + responseNotHandledStatuses = Arrays.stream(value.split(",")). + map(String::trim) + .filter(status -> !status.isEmpty()) + .map(Integer::parseInt) + .collect(Collectors.toSet()); } // ResponseCapture.handledByDefault true/false (true by default) value = config.getInitParameter("responseHandledByDefault"); @@ -180,7 +175,7 @@ public boolean isResetUnhandledResponse() { } public void setResetUnhandledResponse(boolean reset) { - this.resetUnhandledResponse = Boolean.valueOf(reset); + this.resetUnhandledResponse = reset; } public boolean isResetUnhandledResponseBuffer() { @@ -204,10 +199,9 @@ public Collection getResponseNotHandledStatuses() { return this.responseNotHandledStatuses; } - @SuppressWarnings("unchecked") public void setDefaultNotHandledStatuses(final Collection responseNotHandledStatuses) { this.responseNotHandledStatuses = - responseNotHandledStatuses == null ? Collections.EMPTY_SET : responseNotHandledStatuses; + responseNotHandledStatuses == null ? Collections.emptySet() : responseNotHandledStatuses; } public boolean isResponseHandledByDefault() { diff --git a/src/main/java/org/jruby/rack/ext/Input.java b/src/main/java/org/jruby/rack/ext/Input.java index ddd1e1b4d..ba02778d0 100644 --- a/src/main/java/org/jruby/rack/ext/Input.java +++ b/src/main/java/org/jruby/rack/ext/Input.java @@ -62,11 +62,7 @@ public class Input extends RubyObject { CONCAT_WITH_CODERANGE = catWithCR; } - static final ObjectAllocator ALLOCATOR = new ObjectAllocator() { - public IRubyObject allocate(Ruby runtime, RubyClass klass) { - return new Input(runtime, klass); - } - }; + static final ObjectAllocator ALLOCATOR = Input::new; static RubyClass getClass(final Ruby runtime) { final RubyModule _JRuby_Rack = (RubyModule) @@ -268,8 +264,7 @@ private static Method getRewindMethod(InputStream input) { try { return input.getClass().getMethod("rewind", (Class[]) null); } - catch (NoSuchMethodException e) { /* NOOP */ } - catch (SecurityException e) { /* NOOP */ } + catch (NoSuchMethodException | SecurityException e) { /* NOOP */ } return null; } diff --git a/src/main/java/org/jruby/rack/ext/Logger.java b/src/main/java/org/jruby/rack/ext/Logger.java index d8c5b728a..e9951752d 100644 --- a/src/main/java/org/jruby/rack/ext/Logger.java +++ b/src/main/java/org/jruby/rack/ext/Logger.java @@ -55,11 +55,7 @@ @JRubyClass(name="JRuby::Rack::Logger") public class Logger extends RubyObject { // implements RackLogger - static final ObjectAllocator ALLOCATOR = new ObjectAllocator() { - public IRubyObject allocate(Ruby runtime, RubyClass klass) { - return new Logger(runtime, klass); - } - }; + static final ObjectAllocator ALLOCATOR = Logger::new; // Logger::Severity : @@ -581,11 +577,7 @@ public IRubyObject stub(final ThreadContext context) { @JRubyClass(name="JRuby::Rack::ServletLog") public static class ServletLog extends RubyObject { - static final ObjectAllocator ALLOCATOR = new ObjectAllocator() { - public IRubyObject allocate(Ruby runtime, RubyClass klass) { - return new ServletLog(runtime, klass); - } - }; + static final ObjectAllocator ALLOCATOR = ServletLog::new; private RackLogger context; diff --git a/src/main/java/org/jruby/rack/ext/Response.java b/src/main/java/org/jruby/rack/ext/Response.java index 20d05f4e6..911e0201c 100644 --- a/src/main/java/org/jruby/rack/ext/Response.java +++ b/src/main/java/org/jruby/rack/ext/Response.java @@ -50,12 +50,12 @@ import org.jruby.rack.RackException; import org.jruby.rack.RackResponse; import org.jruby.rack.RackResponseEnvironment; -import org.jruby.runtime.Arity; import org.jruby.runtime.Block; import org.jruby.runtime.BlockBody; import org.jruby.runtime.Helpers; import org.jruby.runtime.JavaInternalBlockBody; import org.jruby.runtime.ObjectAllocator; +import org.jruby.runtime.Signature; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.Visibility; import org.jruby.runtime.builtin.IRubyObject; @@ -93,7 +93,7 @@ public static IRubyObject is_swallow_client_abort(final ThreadContext context, f @JRubyMethod(name = "swallow_client_abort=", meta = true, required = 1) public static IRubyObject set_swallow_client_abort(final IRubyObject self, final IRubyObject value) { if ( value instanceof RubyBoolean ) { - swallowClientAbort = ((RubyBoolean) value).isTrue(); + swallowClientAbort = value.isTrue(); } else { swallowClientAbort = ! value.isNil(); @@ -124,7 +124,7 @@ public static IRubyObject is_dechunk(final ThreadContext context, final IRubyObj @JRubyMethod(name = "dechunk=", meta = true, required = 1) public static IRubyObject set_dechunk(final IRubyObject self, final IRubyObject value) { if ( value instanceof RubyBoolean ) { - dechunk = ((RubyBoolean) value).isTrue(); + dechunk = value.isTrue(); } else { dechunk = ! value.isNil(); @@ -138,7 +138,7 @@ public static IRubyObject set_dechunk(final IRubyObject self, final IRubyObject * Returns the channel chunk size to be used e.g. when a (send) file * response is detected. By setting this value to nil you force an "explicit" * byte buffer to be used when copying between channels. - * + *

* Note: High values won't hurt when sending small files since most Java * (file) channel implementations handle this gracefully. However if you're * on Windows it is recommended to not set this higher than the "magic" @@ -169,7 +169,7 @@ public static IRubyObject set_channel_chunk_size(final IRubyObject self, final I } else { final long val = value.convertToInteger("to_i").getLongValue(); - channelChunkSize = Integer.valueOf((int) val); + channelChunkSize = (int) val; } return value; } @@ -204,16 +204,12 @@ public static IRubyObject set_channel_buffer_size(final IRubyObject self, final } else { final long val = value.convertToInteger("to_i").getLongValue(); - channelBufferSize = Integer.valueOf((int) val); + channelBufferSize = (int) val; } return value; } - static final ObjectAllocator ALLOCATOR = new ObjectAllocator() { - public IRubyObject allocate(Ruby runtime, RubyClass klass) { - return new Response(runtime, klass); - } - }; + static final ObjectAllocator ALLOCATOR = Response::new; protected Response(Ruby runtime, RubyClass metaClass) { super(runtime, metaClass); @@ -232,7 +228,7 @@ protected Response(Ruby runtime, RubyClass metaClass) { @JRubyMethod(required = 1) public IRubyObject initialize(final ThreadContext context, final IRubyObject arg) { if ( arg instanceof RubyArray ) { - final RubyArray arr = (RubyArray) arg; + final RubyArray arr = (RubyArray) arg; if ( arr.size() < 3 ) { throw context.runtime.newArgumentError("expected 3 array elements (rack-respose)"); } @@ -298,10 +294,10 @@ public String getBody() { try { final StringBuilder bodyParts = new StringBuilder(); invoke(context, this.body, "each", - new JavaInternalBlockBody(context.runtime, Arity.ONE_REQUIRED) { + new JavaInternalBlockBody(context.runtime, Signature.ONE_REQUIRED) { @Override public IRubyObject yield(ThreadContext context, IRubyObject[] args) { - return yield(context, args[0]); + return this.yield(context, args[0]); } @Override @@ -347,7 +343,7 @@ public void respond(final RackResponseEnvironment response) throws RackException @JRubyMethod(name = "write_status") public IRubyObject write_status(final ThreadContext context, final IRubyObject response) { - writeStatus( (RackResponseEnvironment) response.toJava(RackResponseEnvironment.class) ); + writeStatus(response.toJava(RackResponseEnvironment.class)); return context.nil; } @@ -358,7 +354,7 @@ protected void writeStatus(final RackResponseEnvironment response) { @JRubyMethod(name = "write_headers") public IRubyObject write_headers(final ThreadContext context, final IRubyObject response) throws IOException { - writeHeaders( (RackResponseEnvironment) response.toJava(RackResponseEnvironment.class) ); + writeHeaders(response.toJava(RackResponseEnvironment.class)); return context.nil; } @@ -394,10 +390,10 @@ public void visit(final IRubyObject key, final IRubyObject val) { final RubyString newLine = RubyString.newString(context.runtime, NEW_LINE); // value.each_line { |val| response.addHeader(key.to_s, val.chomp("\n")) } invoke(context, val, each_line ? "each_line" : "each", - new JavaInternalBlockBody(context.runtime, Arity.ONE_REQUIRED) { + new JavaInternalBlockBody(context.runtime, Signature.ONE_REQUIRED) { @Override public IRubyObject yield(ThreadContext context, IRubyObject[] args) { - return yield(context, args[0]); + return this.yield(context, args[0]); } @Override @@ -430,7 +426,7 @@ else if ( val instanceof RubyTime ) { @JRubyMethod(name = "write_body") public IRubyObject write_body(final ThreadContext context, final IRubyObject response) throws IOException { - writeBody( (RackResponseEnvironment) response.toJava(RackResponseEnvironment.class) ); + writeBody(response.toJava(RackResponseEnvironment.class)); return context.nil; } @@ -463,7 +459,7 @@ protected void writeBody(final RackResponseEnvironment response) throws IOExcept else { final ThreadContext context = currentContext(); final IRubyObject channel = body.callMethod(context, "to_channel"); - bodyChannel = (Channel) channel.toJava(Channel.class); + bodyChannel = channel.toJava(Channel.class); } if ( bodyChannel instanceof FileChannel ) { transferChannel( (FileChannel) bodyChannel, response.getOutputStream() ); @@ -486,10 +482,10 @@ protected void writeBody(final RackResponseEnvironment response) throws IOExcept final String method = body.respondsTo("each_line") ? "each_line" : "each"; try { invoke(context, body, method, - new JavaInternalBlockBody(context.runtime, Arity.ONE_REQUIRED) { + new JavaInternalBlockBody(context.runtime, Signature.ONE_REQUIRED) { @Override public IRubyObject yield(ThreadContext context, IRubyObject[] args) { - return yield(context, args[0]); + return this.yield(context, args[0]); } @Override @@ -508,8 +504,7 @@ public IRubyObject yield(ThreadContext context, IRubyObject line) { catch (WrappedException e) { throw e.getIOCause(); } } } - catch (IOException e) { if ( ! handledAsClientAbort(e) ) throw e; } - catch (RuntimeException e) { if ( ! handledAsClientAbort(e) ) throw e; } + catch (IOException | RuntimeException e) { if ( ! handledAsClientAbort(e) ) throw e; } finally { if ( body.respondsTo("close") ) { body.callMethod(currentContext(), "close"); diff --git a/src/main/java/org/jruby/rack/ext/Servlet.java b/src/main/java/org/jruby/rack/ext/Servlet.java index 1933321d3..154a24940 100644 --- a/src/main/java/org/jruby/rack/ext/Servlet.java +++ b/src/main/java/org/jruby/rack/ext/Servlet.java @@ -41,11 +41,7 @@ @JRubyClass(name="Rack::Handler::Servlet") public class Servlet extends RubyObject { - static final ObjectAllocator ALLOCATOR = new ObjectAllocator() { - public IRubyObject allocate(Ruby runtime, RubyClass klass) { - return new Servlet(runtime, klass); - } - }; + static final ObjectAllocator ALLOCATOR = Servlet::new; protected Servlet(Ruby runtime, RubyClass metaClass) { super(runtime, metaClass); diff --git a/src/main/java/org/jruby/rack/servlet/RequestCapture.java b/src/main/java/org/jruby/rack/servlet/RequestCapture.java index d776a3dd0..905cabc2b 100644 --- a/src/main/java/org/jruby/rack/servlet/RequestCapture.java +++ b/src/main/java/org/jruby/rack/servlet/RequestCapture.java @@ -10,8 +10,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; @@ -131,31 +131,28 @@ private boolean parseRequestParams() { catch (IOException e) { /* ignored */ } if (line == null) return false; - final Map params = new HashMap(); + final Map params = new HashMap<>(); final String[] pairs = line.split("\\&"); - for (int i = 0; i < pairs.length; i++) { - try { - String[] fields = pairs[i].split("=", 2); - String key = URLDecoder.decode(fields[0], "UTF-8"); - String value = null; - if (fields.length == 2) { - value = URLDecoder.decode(fields[1], "UTF-8"); - } - if (value != null) { - String[] newValues; - if (params.containsKey(key)) { - String[] values = params.get(key); - newValues = new String[values.length + 1]; - System.arraycopy(values, 0, newValues, 0, values.length); - newValues[values.length] = value; - } else { - newValues = new String[1]; - newValues[0] = value; - } - params.put(key, newValues); + for (String pair : pairs) { + String[] fields = pair.split("=", 2); + String key = URLDecoder.decode(fields[0], StandardCharsets.UTF_8); + String value = null; + if (fields.length == 2) { + value = URLDecoder.decode(fields[1], StandardCharsets.UTF_8); + } + if (value != null) { + String[] newValues; + if (params.containsKey(key)) { + String[] values = params.get(key); + newValues = new String[values.length + 1]; + System.arraycopy(values, 0, newValues, 0, values.length); + newValues[values.length] = value; + } else { + newValues = new String[1]; + newValues[0] = value; } - } - catch (UnsupportedEncodingException e) { /* UTF-8 should be fine */ } + params.put(key, newValues); + } } this.requestParams = params; diff --git a/src/main/java/org/jruby/rack/servlet/ResponseCapture.java b/src/main/java/org/jruby/rack/servlet/ResponseCapture.java index 6fba037b2..acaea98b1 100644 --- a/src/main/java/org/jruby/rack/servlet/ResponseCapture.java +++ b/src/main/java/org/jruby/rack/servlet/ResponseCapture.java @@ -62,7 +62,7 @@ public boolean isStatusSet() { /** * Status code handler customizable by sub-classes. - * + *

* Besides serving as a setter, should return whether the status has been * "accepted" (super methods will be called when this is invoked from response * API methods such as {@link #setStatus(int)}). @@ -87,6 +87,7 @@ public void setStatus(int status) { } @Override + @Deprecated public void setStatus(int status, String message) { if ( handleStatus(status, false) ) { super.setStatus(status, message); @@ -267,10 +268,9 @@ public Collection getNotHandledStatuses() { return this.notHandledStatuses; } - @SuppressWarnings("unchecked") public void setNotHandledStatuses(final Collection notHandledStatuses) { this.notHandledStatuses = - notHandledStatuses == null ? Collections.EMPTY_SET : notHandledStatuses; + notHandledStatuses == null ? Collections.emptySet() : notHandledStatuses; } boolean isHandledByDefault() { diff --git a/src/main/java/org/jruby/rack/servlet/ServletRackEnvironment.java b/src/main/java/org/jruby/rack/servlet/ServletRackEnvironment.java index 4cb7c3136..6a9e16e95 100644 --- a/src/main/java/org/jruby/rack/servlet/ServletRackEnvironment.java +++ b/src/main/java/org/jruby/rack/servlet/ServletRackEnvironment.java @@ -27,7 +27,6 @@ * * @author nicksieger */ -@SuppressWarnings("unchecked") public class ServletRackEnvironment extends HttpServletRequestWrapper implements RackEnvironment { @@ -103,9 +102,9 @@ public String getPathInfo() { final StringBuilder buffer = new StringBuilder(32); final String onlyURI = getRequestURIWithoutQuery(); - if ( onlyURI.length() > 0 ) { + if (!onlyURI.isEmpty()) { final String script = getScriptName(); - if ( script != null && script.length() > 0 + if ( script != null && !script.isEmpty() && onlyURI.indexOf(script) == 0 ) { buffer.append( onlyURI.substring(script.length()) ); } else { diff --git a/src/main/java/org/jruby/rack/util/ExceptionUtils.java b/src/main/java/org/jruby/rack/util/ExceptionUtils.java index bd6cae649..ffe4a7376 100644 --- a/src/main/java/org/jruby/rack/util/ExceptionUtils.java +++ b/src/main/java/org/jruby/rack/util/ExceptionUtils.java @@ -104,7 +104,7 @@ public static void appendBacktrace(final RubyException error, final int skip, final ThreadContext context = error.getRuntime().getCurrentContext(); final IRubyObject backtrace = error.callMethod(context, "backtrace"); if ( ! backtrace.isNil() /* && backtrace instanceof RubyArray */ ) { - final RubyArray trace = backtrace.convertToArray(); + final RubyArray trace = backtrace.convertToArray(); out.ensureCapacity(out.length() + 24 * trace.getLength()); for ( int i = skip; i < trace.getLength(); i++ ) { IRubyObject stackTraceLine = trace.eltInternal(i); From 0a741729345feabb3ee32c87c9530cb1ba7fcc1c Mon Sep 17 00:00:00 2001 From: Chad Wilson <29788154+chadlwilson@users.noreply.github.com> Date: Wed, 23 Jul 2025 11:50:12 +0800 Subject: [PATCH 2/2] Remove dead/commented out code and modifiers --- .../rack/DefaultRackApplicationFactory.java | 3 +- .../org/jruby/rack/DefaultRackConfig.java | 1 - .../rack/PoolingRackApplicationFactory.java | 7 +- .../java/org/jruby/rack/RackApplication.java | 2 +- .../jruby/rack/RackApplicationFactory.java | 2 +- src/main/java/org/jruby/rack/RackConfig.java | 7 +- .../java/org/jruby/rack/RackEnvironment.java | 84 +++++-------------- src/main/java/org/jruby/rack/RackInput.java | 4 - src/main/java/org/jruby/rack/RackLogger.java | 12 --- .../rack/SharedRackApplicationFactory.java | 5 +- .../java/org/jruby/rack/embed/Config.java | 7 -- .../java/org/jruby/rack/embed/Context.java | 3 - src/main/java/org/jruby/rack/ext/Logger.java | 60 +------------ .../java/org/jruby/rack/ext/Response.java | 2 - src/main/java/org/jruby/rack/ext/Servlet.java | 4 - .../rack/logging/OutputStreamLogger.java | 4 +- .../rack/logging/ServletContextLogger.java | 3 - .../servlet/DefaultServletRackContext.java | 2 - .../jruby/rack/servlet/ResponseCapture.java | 1 + .../rack/servlet/RewindableInputStream.java | 5 +- .../org/jruby/rack/util/ExceptionUtils.java | 14 +--- 21 files changed, 40 insertions(+), 192 deletions(-) diff --git a/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java b/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java index c51dcabce..d29d89783 100644 --- a/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java +++ b/src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java @@ -25,6 +25,7 @@ import org.jruby.rack.util.IOHelpers; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; +import org.jruby.util.cli.OutputStrings; import static org.jruby.rack.RackLogger.Level.*; import static org.jruby.rack.DefaultRackConfig.isIgnoreRUBYOPT; @@ -85,7 +86,7 @@ public void init(final RackContext rackContext) { this.rackContext = (ServletRackContext) rackContext; if ( getRackupScript() == null ) resolveRackupScript(); this.runtimeConfig = createRuntimeConfig(); - rackContext.log(INFO, runtimeConfig.getVersionString()); + rackContext.log(INFO, OutputStrings.getVersionString()); configureDefaults(); } diff --git a/src/main/java/org/jruby/rack/DefaultRackConfig.java b/src/main/java/org/jruby/rack/DefaultRackConfig.java index 874be72a1..677c07575 100644 --- a/src/main/java/org/jruby/rack/DefaultRackConfig.java +++ b/src/main/java/org/jruby/rack/DefaultRackConfig.java @@ -416,7 +416,6 @@ private static Map getLoggerTypes() { loggerTypes.put("clogging", "org.jruby.rack.logging.CommonsLoggingLogger"); loggerTypes.put("slf4j", "org.jruby.rack.logging.Slf4jLogger"); loggerTypes.put("jul", "org.jruby.rack.logging.JulLogger"); - //loggerTypes.put("servlet_context", "org.jruby.rack.logging.ServletContextLogger"); return loggerTypes; } diff --git a/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java b/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java index e4c777fb6..775a6a75c 100644 --- a/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java +++ b/src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java @@ -111,7 +111,7 @@ public void setAcquireTimeout(Number acquireTimeout) { @Override protected void doInit() throws Exception { - super.doInit(); // delegate.init(rackContext); + super.doInit(); final RackConfig config = getConfig(); // TODO until config.getRuntimeTimeoutSeconds returns an integer : Number timeout = config.getNumberProperty("jruby.runtime.acquire.timeout"); @@ -253,16 +253,15 @@ public void destroy() { synchronized (applicationPool) { for (RackApplication app : applicationPool) { getDelegate().finishedWithApplication(app); - // DefaultRackAppFactory: app.destroy(); } applicationPool.clear(); } - super.destroy(); // delegate.destroy(); + super.destroy(); } /** * Fills the initial pool with initialized application instances. - * + *

* Application objects are created in foreground threads to avoid * leakage when the web application is undeployed from the server. */ diff --git a/src/main/java/org/jruby/rack/RackApplication.java b/src/main/java/org/jruby/rack/RackApplication.java index 809b553c2..5305d38fd 100644 --- a/src/main/java/org/jruby/rack/RackApplication.java +++ b/src/main/java/org/jruby/rack/RackApplication.java @@ -24,7 +24,7 @@ public interface RackApplication { * @param env the RackEnvironment * @return the RackResponse */ - public RackResponse call(RackEnvironment env); + RackResponse call(RackEnvironment env); /** * Get a reference to the underlying runtime that holds the application diff --git a/src/main/java/org/jruby/rack/RackApplicationFactory.java b/src/main/java/org/jruby/rack/RackApplicationFactory.java index df5bb3853..0cb66ff40 100644 --- a/src/main/java/org/jruby/rack/RackApplicationFactory.java +++ b/src/main/java/org/jruby/rack/RackApplicationFactory.java @@ -68,7 +68,7 @@ public interface RackApplicationFactory { * * @author kares */ - public static interface Decorator { + interface Decorator { /** * @return the delegate factory this decorator wraps diff --git a/src/main/java/org/jruby/rack/RackConfig.java b/src/main/java/org/jruby/rack/RackConfig.java index 2916b8117..442e9e59c 100644 --- a/src/main/java/org/jruby/rack/RackConfig.java +++ b/src/main/java/org/jruby/rack/RackConfig.java @@ -135,12 +135,7 @@ public interface RackConfig { * @return the maximum size of the in-memory buffer */ Integer getMaximumMemoryBufferSize(); - - /** - * @return whether we allow the initialization exception to bubble up - */ - //boolean isThrowInitException(); - + /** * Create a logger to be used (based on this configuration). * @return a logger instance diff --git a/src/main/java/org/jruby/rack/RackEnvironment.java b/src/main/java/org/jruby/rack/RackEnvironment.java index 9f910abc8..ee8f38e54 100644 --- a/src/main/java/org/jruby/rack/RackEnvironment.java +++ b/src/main/java/org/jruby/rack/RackEnvironment.java @@ -27,13 +27,13 @@ public interface RackEnvironment { * Environment key that retrieves the exception the {@link RackApplication} * failed with. Useful when dispatching call to an {@link ErrorApplication}. */ - final String EXCEPTION = "jruby.rack.exception"; - final String DYNAMIC_REQS_ONLY = "jruby.rack.dynamic.requests.only"; + String EXCEPTION = "jruby.rack.exception"; + String DYNAMIC_REQS_ONLY = "jruby.rack.dynamic.requests.only"; /** * @return the associated {@link RackContext} for this environment */ - public RackContext getContext(); + RackContext getContext(); // The following methods are specific to the rack environment @@ -42,14 +42,14 @@ public interface RackEnvironment { * @return the input as a stream * @throws IOException if there's an IO exception */ - public InputStream getInput() throws IOException; + InputStream getInput() throws IOException; /** * For servlet-based environment implementations the script name might be * constructed as the the (servlet) context path + the servlet path. * @return the script name ("CGI" style) */ - public String getScriptName(); + String getScriptName(); // The following methods are usually inherited from the servlet request @@ -57,145 +57,105 @@ public interface RackEnvironment { * @see javax.servlet.http.HttpServletRequest#getPathInfo() * @return the request path info */ - public String getPathInfo(); + String getPathInfo(); /** * Request URI should include the query string if available. * @see javax.servlet.http.HttpServletRequest#getRequestURI() * @return the request URI */ - public String getRequestURI(); + String getRequestURI(); /** * @see javax.servlet.http.HttpServletRequest#getAttributeNames() * @return an enumeration of all attribute names */ - public Enumeration getAttributeNames(); + Enumeration getAttributeNames(); /** * @see javax.servlet.http.HttpServletRequest#getAttribute(String) * @param key the attribute key * @return the attribute value */ - public Object getAttribute(String key); + Object getAttribute(String key); /** * @see javax.servlet.http.HttpServletRequest#setAttribute(String, Object) * @param key the key * @param value the value */ - public void setAttribute(String key, Object value); + void setAttribute(String key, Object value); /** * @see javax.servlet.http.HttpServletRequest#getHeaderNames() * @return an enumeration of all header names */ - public Enumeration getHeaderNames(); + Enumeration getHeaderNames(); /** * @see javax.servlet.http.HttpServletRequest#getHeader(String) * @param name the header name * @return the header value */ - public String getHeader(String name); + String getHeader(String name); /** * @see javax.servlet.http.HttpServletRequest#getScheme() * @return the request scheme */ - public String getScheme(); + String getScheme(); /** * @see javax.servlet.http.HttpServletRequest#getContentType() * @return the content type */ - public String getContentType(); + String getContentType(); /** * @see javax.servlet.http.HttpServletRequest#getContentLength() * @return the content length */ - public int getContentLength(); + int getContentLength(); /** * @see javax.servlet.http.HttpServletRequest#getMethod() * @return the request method */ - public String getMethod(); + String getMethod(); /** * @see javax.servlet.http.HttpServletRequest#getQueryString() * @return the query string */ - public String getQueryString(); + String getQueryString(); /** * @see javax.servlet.http.HttpServletRequest#getServerName() * @return the server name */ - public String getServerName(); + String getServerName(); /** * @see javax.servlet.http.HttpServletRequest#getServerPort() * @return the server port */ - public int getServerPort(); + int getServerPort(); /** * @see javax.servlet.ServletRequest#getRemoteHost() * @return the remote host */ - public String getRemoteHost(); + String getRemoteHost(); /** * @see javax.servlet.ServletRequest#getRemoteAddr() * @return the remote address */ - public String getRemoteAddr(); + String getRemoteAddr(); /** * @see javax.servlet.http.HttpServletRequest#getRemoteUser() * @return the remote user */ - public String getRemoteUser(); - - /** - * {@link RackEnvironment} extension to obtain a rack.input IO. - * - * NOTE: This interface will most likely get moved onto the (parent) - * environment interface directly once the deprecated way of maintaining - * backwards compatibility (using jruby/rack/environment.rb) is removed. - * - * @deprecated Was an internal interface and is no longer used. - * @author kares - */ - @Deprecated - interface ToIO { - - // TODO move to RackEnvironment once jruby/rack/environment.rb removed - - /** - * Convert this environment into a "rack.input" IO. - * Replaces the to_io monkey-patch ... - * @return rack.input - */ - public Input toIO(); - - /** - * Set the rack.input, this is an optional operation and implementers - * might ignore this call silently if they're capable of constructing - * the rack.input themselves. - * @param io the rack.input instance - */ - void setIO(Input io) ; - - } - - /** - * Convert this environment into a "rack.input" IO. - * Replaces the to_io monkey-patch ... - * @return rack.input - */ - //public Input toIO() ; - + String getRemoteUser(); } diff --git a/src/main/java/org/jruby/rack/RackInput.java b/src/main/java/org/jruby/rack/RackInput.java index 4c987ecc9..4f0735a1c 100644 --- a/src/main/java/org/jruby/rack/RackInput.java +++ b/src/main/java/org/jruby/rack/RackInput.java @@ -43,10 +43,6 @@ public static RubyClass getClass(Ruby runtime, String name, RubyClass parent, return runtime.getOrCreateModule("JRuby").getClass(name); // RackInput } - //private static RubyClass getClass(final Ruby runtime) { - // return (RubyClass) runtime.getModule("JRuby").getConstantAt("RackInput"); - //} - public RackInput(Ruby runtime, RubyClass klass) { super(runtime, klass); } diff --git a/src/main/java/org/jruby/rack/RackLogger.java b/src/main/java/org/jruby/rack/RackLogger.java index 91c6b1119..2f30261f4 100644 --- a/src/main/java/org/jruby/rack/RackLogger.java +++ b/src/main/java/org/jruby/rack/RackLogger.java @@ -12,18 +12,6 @@ * @author nicksieger */ public interface RackLogger { - //void debug(String message) ; - //void debug(String message, Throwable e) ; - - //void info(String message) ; - //void info(String message, Throwable e) ; - - //void warn(String message) ; - //void warn(String message, Throwable e) ; - - //void error(String message) ; - //void error(String message, Throwable e) ; - enum Level { DEBUG, INFO, WARN, ERROR, FATAL } diff --git a/src/main/java/org/jruby/rack/SharedRackApplicationFactory.java b/src/main/java/org/jruby/rack/SharedRackApplicationFactory.java index f4f2f63bb..96c0c6807 100644 --- a/src/main/java/org/jruby/rack/SharedRackApplicationFactory.java +++ b/src/main/java/org/jruby/rack/SharedRackApplicationFactory.java @@ -31,7 +31,7 @@ public SharedRackApplicationFactory(RackApplicationFactory delegate) { @Override protected void doInit() throws Exception { - super.doInit(); // delegate.init(rackContext); + super.doInit(); log(INFO, "using a shared (thread-safe) runtime"); application = getDelegate().getApplication(); } @@ -62,11 +62,10 @@ public void destroy() { synchronized(this) { if (application != null) { getDelegate().finishedWithApplication(application); - // DefaultRackAppFactory: application.destroy(); } } } - super.destroy(); // delegate.destroy(); + super.destroy(); } @Override diff --git a/src/main/java/org/jruby/rack/embed/Config.java b/src/main/java/org/jruby/rack/embed/Config.java index 707873451..2235f2403 100644 --- a/src/main/java/org/jruby/rack/embed/Config.java +++ b/src/main/java/org/jruby/rack/embed/Config.java @@ -147,37 +147,30 @@ public String getRackupPath() { // runtime pooling in embedded ENVs not implemented : public Integer getRuntimeTimeoutSeconds() { - //return delegate.getRuntimeTimeoutSeconds(); throw new UnsupportedOperationException("getRuntimeTimeoutSeconds()"); } public Integer getInitialRuntimes() { - //return delegate.getInitialRuntimes(); throw new UnsupportedOperationException("getInitialRuntimes()"); } public Integer getMaximumRuntimes() { - //return delegate.getMaximumRuntimes(); throw new UnsupportedOperationException("getMaximumRuntimes()"); } public String[] getRuntimeArguments() { - //return delegate.getRuntimeArguments(); throw new UnsupportedOperationException("getRuntimeArguments()"); } public Integer getNumInitializerThreads() { - //return delegate.getNumInitializerThreads(); throw new UnsupportedOperationException("getNumInitializerThreads()"); } public boolean isSerialInitialization() { - //return delegate.isSerialInitialization(); throw new UnsupportedOperationException("isSerialInitialization()"); } public boolean isIgnoreEnvironment() { - //return delegate.isIgnoreEnvironment(); throw new UnsupportedOperationException("isIgnoreEnvironment()"); } diff --git a/src/main/java/org/jruby/rack/embed/Context.java b/src/main/java/org/jruby/rack/embed/Context.java index 6093a4190..41350b723 100644 --- a/src/main/java/org/jruby/rack/embed/Context.java +++ b/src/main/java/org/jruby/rack/embed/Context.java @@ -28,7 +28,6 @@ public class Context implements RackContext, RackLogger { */ public Context(final String serverInfo) { this(serverInfo, new Config()); - //this.config.setLogger(this); } /** @@ -114,7 +113,6 @@ public void log(Level level, String message) { final PrintStream out = config.getOut(); out.print(level); out.print(": "); printMessage(out, message); - // out.flush(); } @Override @@ -123,7 +121,6 @@ public void log(Level level, String message, Throwable ex) { err.print(level); err.print(": "); printMessage(err, message); ex.printStackTrace(err); - // err.flush(); } @Override diff --git a/src/main/java/org/jruby/rack/ext/Logger.java b/src/main/java/org/jruby/rack/ext/Logger.java index e9951752d..b99e03cad 100644 --- a/src/main/java/org/jruby/rack/ext/Logger.java +++ b/src/main/java/org/jruby/rack/ext/Logger.java @@ -77,7 +77,6 @@ public class Logger extends RubyObject { // implements RackLogger private int level = NOT_SET; private RackLogger logger; // the "real" logger - //private Boolean loggerFormatting; private IRubyObject formatter = null; // optional private IRubyObject progname; @@ -220,11 +219,8 @@ public IRubyObject get_formatter(final ThreadContext context) { public IRubyObject set_formatter(final ThreadContext context, final IRubyObject formatter) { if ( logger instanceof RackLogger.Base ) { final RackLogger.Base logger = (RackLogger.Base) this.logger; - //if ( loggerFormatting == null ) loggerFormatting = logger.isFormatting(); if ( formatter.isNil() ) { - //if ( loggerFormatting != null && loggerFormatting.booleanValue() ) { - logger.setFormatting(true); - //} + logger.setFormatting(true); } else { // if formatter set disable 'potential' logger formatting logger.setFormatting(false); @@ -381,9 +377,6 @@ private boolean add(final int severity, final ThreadContext context, progname = msg; msg = block.yieldSpecific(context); } - else { - //msg = progname; - } } if ( formatter != null ) { // formatter is optional and null by default if ( progname == null ) { @@ -462,20 +455,6 @@ private static ByteList formatSeverity(final int severity) { return FORMATTED_ANY; } - /* - private static String formatSeverity(final int severity) { - switch ( severity) { - case DEBUG: return "DEBUG"; - case INFO : return "INFO" ; - case WARN : return "WARN" ; - case ERROR: return "ERROR"; - case FATAL: return "FATAL"; - } - return "ANY"; - } */ - - // RackLogger - @Override public T toJava(Class target) { // NOTE: maybe this is not a good idea ?! @@ -495,37 +474,6 @@ private void doLog(RubyString message) { logger.log( message.toString() ); } - /* - @Override - public void log(String message) { - logger.log(message); - } - - @Override - public void log(String message, Throwable ex) { - logger.log(message, ex); - } - - @Override - public void log(Level level, String message) { - logger.log(level, message); - } - - @Override - public void log(Level level, String message, Throwable ex) { - logger.log(level, message, ex); - } - - @Override @Deprecated - public void log(String level, String message) { - logger.log(level, message); - } - - @Override @Deprecated - public void log(String level, String message, Throwable ex) { - logger.log(level, message, ex); - } */ - // LoggerSilence API : private static boolean silencer = false; // we're NOT true by default! @@ -554,10 +502,8 @@ public IRubyObject silence(final ThreadContext context, final IRubyObject temp_l private IRubyObject doSilence(final int tempLevel, final ThreadContext context, final Block block) { if ( silencer ) { - try { // not implemented - on purpose! - return block.yield(context, this); - } - finally { /* noop */ } + // not implemented - on purpose! + return block.yield(context, this); } else { return block.yield(context, this); diff --git a/src/main/java/org/jruby/rack/ext/Response.java b/src/main/java/org/jruby/rack/ext/Response.java index 911e0201c..e150c77a0 100644 --- a/src/main/java/org/jruby/rack/ext/Response.java +++ b/src/main/java/org/jruby/rack/ext/Response.java @@ -490,10 +490,8 @@ public IRubyObject yield(ThreadContext context, IRubyObject[] args) { @Override public IRubyObject yield(ThreadContext context, IRubyObject line) { - //final ByteList bytes = line.asString().getByteList(); try { output.write( line.asString().getBytes() ); - //output.write(bytes.unsafeBytes(), bytes.getBegin(), bytes.getRealSize()); if ( doFlush() ) output.flush(); } catch (IOException e) { throw new WrappedException(e); } diff --git a/src/main/java/org/jruby/rack/ext/Servlet.java b/src/main/java/org/jruby/rack/ext/Servlet.java index 154a24940..5bd049615 100644 --- a/src/main/java/org/jruby/rack/ext/Servlet.java +++ b/src/main/java/org/jruby/rack/ext/Servlet.java @@ -59,10 +59,6 @@ public IRubyObject initialize(final IRubyObject app) { throw getRuntime().newArgumentError( "rack app not found, make sure the rackup file path is correct"); } - //if ( ! app.respondsTo("call") ) { - // throw getRuntime().newArgumentError( - // "passed rack app does not respond to #call : " + app.toString()); - //} this.app = app; return this; } diff --git a/src/main/java/org/jruby/rack/logging/OutputStreamLogger.java b/src/main/java/org/jruby/rack/logging/OutputStreamLogger.java index 15f6cd6db..c20be6629 100644 --- a/src/main/java/org/jruby/rack/logging/OutputStreamLogger.java +++ b/src/main/java/org/jruby/rack/logging/OutputStreamLogger.java @@ -61,12 +61,12 @@ public void setLevel(Level level) { @Override public void log(String message) { - doLog(message); // log(Level.INFO, message); + doLog(message); } @Override public void log(String message, Throwable ex) { - doLog(message, ex); // log(Level.ERROR, message, ex); + doLog(message, ex); } @Override diff --git a/src/main/java/org/jruby/rack/logging/ServletContextLogger.java b/src/main/java/org/jruby/rack/logging/ServletContextLogger.java index 8054fb451..c8d8e0563 100644 --- a/src/main/java/org/jruby/rack/logging/ServletContextLogger.java +++ b/src/main/java/org/jruby/rack/logging/ServletContextLogger.java @@ -14,7 +14,6 @@ public class ServletContextLogger extends RackLogger.Base { private final ServletContext context; - //private Level level; //= Level.DEBUG; public ServletContextLogger(ServletContext context) { this.context = context; @@ -43,8 +42,6 @@ public void log(Level level, String message, Throwable ex) { @Override public boolean isEnabled(Level level) { return true; - //if ( level == null || this.level == null ) return true; - //return this.level.ordinal() <= level.ordinal(); } @Override diff --git a/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java b/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java index ccf08fca5..0627081ba 100644 --- a/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java +++ b/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java @@ -242,8 +242,6 @@ public void log(Level level, String message, Throwable e) { logger.log(level, message, e); } - // Servlet 3.0 - @Override public int getEffectiveMajorVersion() throws UnsupportedOperationException { return context.getEffectiveMajorVersion(); diff --git a/src/main/java/org/jruby/rack/servlet/ResponseCapture.java b/src/main/java/org/jruby/rack/servlet/ResponseCapture.java index acaea98b1..eb7a68f50 100644 --- a/src/main/java/org/jruby/rack/servlet/ResponseCapture.java +++ b/src/main/java/org/jruby/rack/servlet/ResponseCapture.java @@ -86,6 +86,7 @@ public void setStatus(int status) { } } + @SuppressWarnings("deprecation") @Override @Deprecated public void setStatus(int status, String message) { diff --git a/src/main/java/org/jruby/rack/servlet/RewindableInputStream.java b/src/main/java/org/jruby/rack/servlet/RewindableInputStream.java index ac5dfbc7a..e939d8665 100644 --- a/src/main/java/org/jruby/rack/servlet/RewindableInputStream.java +++ b/src/main/java/org/jruby/rack/servlet/RewindableInputStream.java @@ -108,7 +108,7 @@ public RewindableInputStream(InputStream input, int bufferSize) { * @param maxBufferSize maximum buffer size (when reached content gets written into a file) */ public RewindableInputStream(InputStream input, int iniBufferSize, int maxBufferSize) { - this.input = input; // super(input); + this.input = input; this.buffer = ByteBuffer.allocate(iniBufferSize); this.buffer.limit(0); // empty this.bufferMax = maxBufferSize; @@ -170,7 +170,6 @@ public synchronized int read() throws IOException { if (fillBuffer(1) == -1) return -1; // EOF - //this.position++; // track stream position return this.buffer.get() & 0xFF; } @@ -187,7 +186,6 @@ public synchronized int read(byte[] buffer, final int offset, final int length) final int len = fillBuffer(length - count); if (len == -1) return count == 0 ? -1 : count; // EOF - //this.position += len; // track stream position this.buffer.get(buffer, offset + count, len); count += len; } @@ -383,7 +381,6 @@ private void setPosition(final long position) throws IOException { else { this.buffer.rewind().position((int) position); } - //this.position = position; } long getPosition() throws IOException { diff --git a/src/main/java/org/jruby/rack/util/ExceptionUtils.java b/src/main/java/org/jruby/rack/util/ExceptionUtils.java index ffe4a7376..45a82cfb1 100644 --- a/src/main/java/org/jruby/rack/util/ExceptionUtils.java +++ b/src/main/java/org/jruby/rack/util/ExceptionUtils.java @@ -41,12 +41,6 @@ */ public abstract class ExceptionUtils { - public static RaiseException wrapException(final Ruby runtime, final Exception cause) { - if ( cause instanceof RaiseException ) return (RaiseException) cause; - NativeException nativeException = new NativeException(runtime, runtime.getNativeException(), cause); - return new RaiseException(cause, nativeException); // getCause() != null - } - public static RaiseException newRuntimeError(final Ruby runtime, final Throwable cause) { return newRaiseException(runtime, runtime.getRuntimeError(), cause); } @@ -61,11 +55,6 @@ public static RaiseException newIOError(final Ruby runtime, final IOException ca return raise; } - static RaiseException newRaiseException(final Ruby runtime, - final RubyClass errorClass, final String message) { - return new RaiseException(runtime, errorClass, message, true); - } - private static RaiseException newRaiseException(final Ruby runtime, final RubyClass errorClass, final Throwable cause) { final String message = cause.getMessage(); @@ -103,7 +92,7 @@ public static void appendBacktrace(final RubyException error, final int skip, final StringBuilder out) { final ThreadContext context = error.getRuntime().getCurrentContext(); final IRubyObject backtrace = error.callMethod(context, "backtrace"); - if ( ! backtrace.isNil() /* && backtrace instanceof RubyArray */ ) { + if ( ! backtrace.isNil() ) { final RubyArray trace = backtrace.convertToArray(); out.ensureCapacity(out.length() + 24 * trace.getLength()); for ( int i = skip; i < trace.getLength(); i++ ) { @@ -113,7 +102,6 @@ public static void appendBacktrace(final RubyException error, final int skip, } } } - //return out; } }