Skip to content

Commit 185d42e

Browse files
committed
[chore] Minor code inspection & style fixes for modern Java
1 parent d9b0b55 commit 185d42e

16 files changed

+36
-110
lines changed

src/main/java/org/jruby/rack/DefaultErrorApplication.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.io.PrintWriter;
2828
import java.io.StringWriter;
2929
import java.util.Collections;
30-
import java.util.Iterator;
3130
import java.util.Map;
3231
import java.util.Set;
3332

@@ -62,14 +61,6 @@ public Ruby getRuntime() {
6261
throw new UnsupportedOperationException("getRuntime() not supported");
6362
}
6463

65-
public void init() {
66-
// NOOP
67-
}
68-
69-
public void destroy() {
70-
// NOOP
71-
}
72-
7364
@Override
7465
public RackResponse call(RackEnvironment env) throws RackException {
7566
return new Response(env); // backwards compatibility

src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class DefaultRackApplicationFactory implements RackApplicationFactory {
4545
private String rackupScript, rackupLocation;
4646
private ServletRackContext rackContext;
4747
private RubyInstanceConfig runtimeConfig;
48-
private RackApplication errorApplication;
48+
private volatile RackApplication errorApplication;
4949

5050
/**
5151
* Convenience helper for unwrapping a {@link RackApplicationFactoryDecorator}.
@@ -351,7 +351,7 @@ public void initRuntime(final Ruby runtime) {
351351
String dechunk = rackContext.getConfig().getProperty("jruby.rack.response.dechunk");
352352
Boolean dechunkFlag = (Boolean) DefaultRackConfig.toStrictBoolean(dechunk, null);
353353
if ( dechunkFlag != null ) {
354-
runtime.evalScriptlet("JRuby::Rack::Response.dechunk = " + dechunkFlag + "");
354+
runtime.evalScriptlet("JRuby::Rack::Response.dechunk = " + dechunkFlag);
355355
}
356356
else { // dechunk null (default) or not a true/false value ... we're patch :
357357
runtime.evalScriptlet("JRuby::Rack::Booter.on_boot { require 'jruby/rack/chunked' }");
@@ -360,7 +360,7 @@ public void initRuntime(final Ruby runtime) {
360360
String swallowAbort = rackContext.getConfig().getProperty("jruby.rack.response.swallow_client_abort");
361361
Boolean swallowAbortFlag = (Boolean) DefaultRackConfig.toStrictBoolean(swallowAbort, null);
362362
if ( swallowAbortFlag != null ) {
363-
runtime.evalScriptlet("JRuby::Rack::Response.swallow_client_abort = " + swallowAbortFlag + "");
363+
runtime.evalScriptlet("JRuby::Rack::Response.swallow_client_abort = " + swallowAbortFlag);
364364
}
365365
}
366366

src/main/java/org/jruby/rack/DefaultRackConfig.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static boolean isIgnoreRUBYOPT(RackConfig config) {
265265
// RUBYOPT ignored if jruby.runtime.env.rubyopt = false
266266
Boolean rubyopt = config.getBooleanProperty("jruby.runtime.env.rubyopt");
267267
if ( rubyopt == null ) return ! config.isIgnoreEnvironment();
268-
return rubyopt != null && !rubyopt;
268+
return !rubyopt;
269269
}
270270

271271
@Override
@@ -283,10 +283,7 @@ static boolean isThrowInitException(RackConfig config) {
283283
return false; // jruby.rack.error = true
284284
}
285285
error = config.getBooleanProperty(RackEnvironment.EXCEPTION);
286-
if ( error != null && error) {
287-
return false; // jruby.rack.exception = true
288-
}
289-
return true;
286+
return error == null || !error; // jruby.rack.exception != true
290287
}
291288

292289
@Override
@@ -391,7 +388,7 @@ private Map<String, String> toStringMap(final String env) {
391388
for ( final String entry : entries ) {
392389
String[] pair = entry.split("=", 2);
393390
if ( pair.length == 1 ) { // no = separator
394-
if ( entry.trim().length() == 0 ) continue;
391+
if ( entry.isBlank() ) continue;
395392
if ( lastKey == null ) continue; // missing key
396393
map.put( lastKey, lastVal = lastVal + ',' + entry );
397394
}

src/main/java/org/jruby/rack/PoolingRackApplicationFactory.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,9 @@ else if ( permit && ( initialSize != null &&
168168
// could only happen if the initialization threads are still
169169
// running (and we've been configured to not wait till all
170170
// 'initial' applications are put to the pool on #init())
171-
while (true) { // thus we'll wait for another pool put ...
171+
do { // thus we'll wait for another pool put ...
172172
waitForApplication();
173-
if ( ! applicationPool.isEmpty() ) break;
174-
}
173+
} while (applicationPool.isEmpty());
175174
app = applicationPool.remove();
176175
}
177176
}
@@ -197,7 +196,7 @@ else if ( permit && ( initialSize != null &&
197196
protected boolean acquireApplicationPermit() throws AcquireTimeoutException {
198197
// NOTE: permits are only used if a pool maximum is specified !
199198
if (permits != null) {
200-
boolean acquired = false;
199+
boolean acquired;
201200
try {
202201
final long timeout = (long) (acquireTimeout * 1000);
203202
acquired = permits.tryAcquire(timeout, TimeUnit.MILLISECONDS);
@@ -328,7 +327,7 @@ private boolean initAndPutApplicationToPool(final RackApplication app) {
328327
}
329328

330329
protected Queue<RackApplication> createApplications() throws RackInitializationException {
331-
Queue<RackApplication> apps = new LinkedList<RackApplication>();
330+
Queue<RackApplication> apps = new LinkedList<>();
332331
for (int i = 0; i < initialSize; i++) {
333332
apps.add( createApplication(false) );
334333
}
@@ -376,7 +375,6 @@ private void waitForApplication() {
376375
applicationPool.wait(5 * 1000);
377376
}
378377
catch (InterruptedException ignore) {
379-
return;
380378
}
381379
}
382380
}

src/main/java/org/jruby/rack/RackEnvironment.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package org.jruby.rack;
99

10-
import org.jruby.rack.ext.Input;
1110
import java.io.IOException;
1211
import java.io.InputStream;
1312
import java.util.Enumeration;

src/main/java/org/jruby/rack/RackException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static String exceptionMessage(final RaiseException e) {
5353
st.append(e.getException().toString()).append('\n');
5454
ByteArrayOutputStream b = new ByteArrayOutputStream();
5555
e.getException().printBacktrace(new PrintStream(b));
56-
st.append(b.toString());
56+
st.append(b);
5757
return st.toString();
5858
}
5959
return null;

src/main/java/org/jruby/rack/SerialPoolingRackApplicationFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected void launchInitialization(final Queue<RackApplication> apps) {
4040

4141
@Override
4242
protected void waitTillPoolReady() {
43-
return; // waiting makes no sense here as we're initializing serialy
43+
// waiting makes no sense here as we're initializing serialy
4444
}
4545

4646
}

src/main/java/org/jruby/rack/SharedRackApplicationFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
public class SharedRackApplicationFactory extends RackApplicationFactoryDecorator {
2525

26-
private RackApplication application;
26+
private volatile RackApplication application;
2727

2828
public SharedRackApplicationFactory(RackApplicationFactory delegate) {
2929
super(delegate);

src/main/java/org/jruby/rack/UnmappedRackFilter.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,12 @@ public class UnmappedRackFilter extends AbstractFilter {
4242

4343
private boolean responseHandledByDefault = true;
4444

45-
private static final Collection<Integer> RESPONSE_NOT_HANDLED_STATUSES;
46-
static {
47-
final Set<Integer> statuses = new HashSet<>(8, 1);
48-
statuses.add( 404 );
49-
// 403 due containers not supporting PUT/DELETE correctly (Tomcat 6)
50-
statuses.add( 403 );
51-
// 405 returned by Jetty 7/8 on PUT/DELETE requests by default
52-
statuses.add( 405 );
53-
// 501 is returned for non standard http verbs like PATCH
54-
statuses.add( 501 );
55-
RESPONSE_NOT_HANDLED_STATUSES = Collections.unmodifiableSet(statuses);
56-
}
45+
private static final Collection<Integer> RESPONSE_NOT_HANDLED_STATUSES = Set.of(
46+
404,
47+
403, // 403 due to containers not supporting PUT/DELETE correctly (Tomcat 6)
48+
405, // 405 returned by Jetty 7/8 on PUT/DELETE requests by default
49+
501 // 501 is returned for non standard http verbs like PATCH
50+
);
5751

5852
private Collection<Integer> responseNotHandledStatuses = RESPONSE_NOT_HANDLED_STATUSES;
5953
private RackContext context;
@@ -91,7 +85,7 @@ public void init(FilterConfig config) throws ServletException {
9185
map(String::trim)
9286
.filter(status -> !status.isEmpty())
9387
.map(Integer::parseInt)
94-
.collect(Collectors.toSet());
88+
.collect(Collectors.toUnmodifiableSet());
9589
}
9690
// ResponseCapture.handledByDefault true/false (true by default)
9791
value = config.getInitParameter("responseHandledByDefault");

src/main/java/org/jruby/rack/embed/Filter.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
*/
88
package org.jruby.rack.embed;
99

10-
import javax.servlet.FilterConfig;
11-
import javax.servlet.ServletException;
12-
1310
import org.jruby.rack.AbstractFilter;
1411
import org.jruby.rack.RackContext;
1512
import org.jruby.rack.RackDispatcher;
@@ -39,10 +36,4 @@ protected RackContext getContext() {
3936
protected RackDispatcher getDispatcher() {
4037
return this.dispatcher;
4138
}
42-
43-
@Override
44-
public void init(FilterConfig config) throws ServletException {
45-
// NOOP
46-
}
47-
4839
}

0 commit comments

Comments
 (0)