Skip to content

Commit

Permalink
Enable Checkstyle (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored May 20, 2024
1 parent ded8d88 commit 3605a77
Show file tree
Hide file tree
Showing 26 changed files with 259 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public S resolveScript(String name) throws E {
script = parseScript(res);
} finally {
LOGGER.log(Level.FINE, "cache miss; took {0}ms to parse {1}", new Object[] {
(System.nanoTime() - start) / 1_000_000, res
(System.nanoTime() - start) / 1_000_000, res,
});
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ private static byte[] readClass(final InputStream is) throws IOException {
* @param classVisitor the visitor that must visit this class.
*/
private void accept(final TypeCollector classVisitor) {
char[] c = new char[maxStringLength]; // buffer used to read strings
int i, j, k; // loop variables
int u, v, w; // indexes in b

Expand Down Expand Up @@ -567,6 +566,8 @@ private void accept(final TypeCollector classVisitor) {
}
}

char[] c = new char[maxStringLength]; // buffer used to read strings

// visits the methods
i = readUnsignedShort(u);
u += 2;
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/org/kohsuke/stapler/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ public Function computeValue(Class<?> from) {
switch (methods.size()) {
case 0:
return RETURN_NULL;
default:
throw new IllegalArgumentException("Too many 'fromStapler' methods on " + from);
case 1:
Method m = ((MethodFunction) methods.get(0)).m;
return new MethodFunction(m) {
Expand All @@ -260,6 +258,8 @@ public Object invoke(StaplerRequest req, StaplerResponse rsp, Object o, Object..
return m.invoke(null, args);
}
};
default:
throw new IllegalArgumentException("Too many 'fromStapler' methods on " + from);
}
}
};
Expand Down Expand Up @@ -293,6 +293,8 @@ final Function wrapByInterceptors(AnnotatedElement m) {
case PREINVOKE:
f = new PreInvokeInterceptedFunction(f, i);
break;
default:
throw new IllegalArgumentException("Unknown Stage: " + ia.stage());
}
} catch (InstantiationException e) {
throw (Error)
Expand Down
34 changes: 17 additions & 17 deletions core/src/main/java/org/kohsuke/stapler/HttpDeletable.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@ public interface HttpDeletable {
* Called when HTTP DELETE method is invoked.
*/
void delete(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException;
}

/**
* {@link Dispatcher} that processes {@link HttpDeletable}
*/
class HttpDeletableDispatcher extends Dispatcher {
@Override
public boolean dispatch(RequestImpl req, ResponseImpl rsp, Object node)
throws IOException, ServletException, IllegalAccessException, InvocationTargetException {
if (!req.tokens.hasMore() && req.getMethod().equals("DELETE")) {
((HttpDeletable) node).delete(req, rsp);
return true;
}
/**
* {@link Dispatcher} that processes {@link HttpDeletable}
*/
class HttpDeletableDispatcher extends Dispatcher {
@Override
public boolean dispatch(RequestImpl req, ResponseImpl rsp, Object node)
throws IOException, ServletException, IllegalAccessException, InvocationTargetException {
if (!req.tokens.hasMore() && req.getMethod().equals("DELETE")) {
((HttpDeletable) node).delete(req, rsp);
return true;
}

return false;
}
return false;
}

@Override
public String toString() {
return "delete() for url=/ with DELETE";
@Override
public String toString() {
return "delete() for url=/ with DELETE";
}
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/MetaClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class MetaClass extends TearOffSupport {
dispatchers.add(new DirectoryishDispatcher());

if (HttpDeletable.class.isAssignableFrom(clazz)) {
dispatchers.add(new HttpDeletableDispatcher());
dispatchers.add(new HttpDeletable.HttpDeletableDispatcher());
}

// check action <obj>.do<token>(...) and other WebMethods
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/org/kohsuke/stapler/Stapler.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public class Stapler extends HttpServlet {
*/
private boolean diagnosticThreadName = true;

public @Override void init(ServletConfig servletConfig) throws ServletException {
@Override
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
this.context = servletConfig.getServletContext();
this.webApp = WebApp.get(context);
Expand Down Expand Up @@ -188,8 +189,8 @@ public WebApp getWebApp() {
this.webApp = webApp;
}

protected @Override void service(HttpServletRequest req, HttpServletResponse rsp)
throws ServletException, IOException {
@Override
protected void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
Thread t = Thread.currentThread();
final String oldName = t.getName();
try {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/StaplerRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,11 @@ public interface StaplerRequest extends HttpServletRequest {
/**
* Obtains a commons-fileupload object that represents an uploaded file.
*
* @deprecated use {@link #getFileItem2(String)}
* @return
* null if a file of the given form field name doesn't exist.
* This includes the case where the name corresponds to a simple
* form field (like textbox, checkbox, etc.)
* @deprecated use {@link #getFileItem2(String)}
*/
@Deprecated
org.apache.commons.fileupload.FileItem getFileItem(String name) throws ServletException, IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ public void serveFile(StaplerRequest req, InputStream data, long lastModified, i
getWrapped().serveFile(req, data, lastModified, contentLength, fileName);
}

/** {@inheritDoc} */
/**
* @deprecated Use {@link #serveExposedBean(StaplerRequest, Object, ExportConfig)}
*/
@Override
@Deprecated
public void serveExposedBean(StaplerRequest req, Object exposedBean, Flavor flavor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public static boolean isValidJavaIdentifier(String name) {
* This serves the script content for a bound object. Support CSP-compatible st:bind and similar methods of making
* objects accessible to JS.
*
* @param req
* @param rsp
* @param req The request
* @param rsp The response
* @param var the variable name to assign the Stapler proxy to
* @param methods the list of methods (needed for {@link WithWellKnownURL})
* @throws IOException
* @throws IOException If an I/O error occurs
*/
public void doScript(
StaplerRequest req, StaplerResponse rsp, @QueryParameter String var, @QueryParameter String methods)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public <T> Model<T> get(Class<T> type) throws NotExportableException {
}

/**
* @throws NotExportableException if type is not exportable
* @return model
* @throws NotExportableException if type is not exportable
*/
@NonNull
public <T> Model<T> get(Class<T> type, @CheckForNull Class<?> propertyOwner, @Nullable String property)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

import java.io.IOException;

/** not needed as of Java 6 */
/**
* not needed as of Java 6
*
* @deprecated use {@link IOException}
*/
@Deprecated
public class IOException2 extends IOException {
public IOException2() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ public static class ArraysWithPluralProperties {
@Test
public void testToSingularWithPluralProperties() throws Exception {
assertEquals(
"<arraysWithPluralProperties _class='ArraysWithPluralProperties'><bars>foo</bars><category>general</category><category>specific</category><foos>foo</foos><style>ornate</style><style>plain</style></arraysWithPluralProperties>",
"<arraysWithPluralProperties _class='ArraysWithPluralProperties'><bars>foo</bars><category>general</category><category>specific</category>"
+ "<foos>foo</foos><style>ornate</style><style>plain</style></arraysWithPluralProperties>",
serialize(new ArraysWithPluralProperties(), ArraysWithPluralProperties.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public void handleAlert(Page page, String message) {
}
}

@JsonOutputFilter(excludes = {"secret"})
@JsonOutputFilter(excludes = "secret")
@JavaScriptMethod
public MyData getSomeExcludedData() {
return new MyData("Bob", "the builder", "super secret value");
}

@JsonOutputFilter(excludes = {"secret"})
@JsonOutputFilter(excludes = "secret")
@JavaScriptMethod
public List<MyData> getSomeExcludedList() {
return Arrays.asList(
Expand All @@ -108,7 +108,7 @@ public List<MyData> getSomeExcludedList() {
new MyData("Jenkins", "the butler", "really secret as well"));
}

@JsonOutputFilter(includes = {"name"})
@JsonOutputFilter(includes = "name")
@JavaScriptMethod
public MyData getSomeIncludedData() {
return new MyData("Bob", "the builder", "super secret value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ConstructorProcessorTest {
"import org.kohsuke.stapler.DataBoundConstructor;",
"public class Stuff {",
" @DataBoundConstructor public Stuff(int count, String name) {}",
"}",
"}"
})
@Test
void basicOutput(Results results) {
Expand Down Expand Up @@ -67,9 +67,7 @@ void preAnnotationCompatibility(Results results) {
" @DataBoundConstructor public Stuff(int count, String name) {}",
"}"
})
@Inline(
name = "some.pkg.package-info",
source = {"package some.pkg;"})
@Inline(name = "some.pkg.package-info", source = "package some.pkg;")
@Test
void JENKINS_11739(Results results) {
assertEquals(Collections.emptyList(), results.diagnostics);
Expand Down Expand Up @@ -179,7 +177,7 @@ void duplicatedButNotAnnotatedConstructor(Results results) {
"import org.kohsuke.stapler.DataBoundConstructor;",
"public class Stuff {",
" @DataBoundConstructor public Stuff(int count, String name) {}",
"}",
"}"
})
@Test
void reproducibleBuild(Results results) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

@ExtendWith(JavacExtension.class)
@Options("-Werror")
@Processors({
AnnotationProcessorImpl.class,
ExportedBeanAnnotationProcessor.class,
})
@Processors({AnnotationProcessorImpl.class, ExportedBeanAnnotationProcessor.class})
class ExportedBeanAnnotationProcessorTest {

private void assertEqualsCRLF(String s1, String s2) {
Expand Down Expand Up @@ -83,7 +80,7 @@ void noJavadoc(Results results) {
"import org.kohsuke.stapler.export.*;",
"@ExportedBean public abstract class Super {",
" @Exported public abstract int getCount();",
"}",
"}"
})
@Inline(
name = "some.pkg.Stuff",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class QueryParameterAnnotationProcessorTest {
"public class Stuff {",
" public void doOneThing(@QueryParameter String key) {}",
" public void doAnother(@QueryParameter(\"ignoredHere\") String name, @QueryParameter String address) {}",
"}",
"}"
})
@Test
void basicOutput(Results results) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public GroovierJellyScript parseScript(URL res) throws IOException {

/**
* Creates a {@link RequestDispatcher} that forwards to the jelly view, if available.
*
* @deprecated removed without replacement
*/
@Deprecated
public RequestDispatcher createDispatcher(Object it, String viewName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
public abstract class GroovyClosureScript extends Script {
private GroovyObject delegate;

protected GroovyClosureScript() {
super();
}
protected GroovyClosureScript() {}

protected GroovyClosureScript(Binding binding) {
super(binding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public GroovierJellyScript parseScript(URL res) throws IOException {

/**
* Creates a {@link RequestDispatcher} that forwards to the jelly view, if available.
*
* @deprecated removed without replacement
*/
@Deprecated
public RequestDispatcher createDispatcher(Object it, String viewName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ public boolean has(Kind k) {
return hasCss;
case JS:
return hasJavaScript;
default:
throw new IllegalArgumentException("Unknown Kind: " + k);
}
throw new AssertionError(k);
}

public void write(StaplerRequest req, XMLOutput out) throws SAXException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public NoSuchAdjunctException(String message, Throwable cause) {
}

public NoSuchAdjunctException(Throwable cause) {
super();
initCause(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

package org.kohsuke.stapler.jelly;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.jelly.JellyContext;
Expand Down Expand Up @@ -94,7 +93,6 @@ public List<Expression> getArguments() {
* Note: this code is also copied into idea-stapler-plugin,
* so don't forget to update that when this code changes.
*/
@SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT", justification = "No default needed.")
private String tokenize(String text) throws JellyException {
int parenthesis = 0;
for (int idx = 0; idx < text.length(); idx++) {
Expand Down Expand Up @@ -124,6 +122,8 @@ private String tokenize(String text) throws JellyException {
// skip strings
idx = text.indexOf(ch, idx + 1);
break;
default:
break;
}
}
throw new JellyException(expressionText + " is missing ')' at the end");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public Script resolveScript(String name) throws JellyException {

/**
* Serves {@code index.jelly} if it's available, and returns true.
*
* @deprecated removed without replacement
*/
@Deprecated
public boolean serveIndexJelly(StaplerRequest req, StaplerResponse rsp, Object node)
Expand Down Expand Up @@ -125,6 +127,8 @@ public boolean serveIndexJelly(StaplerRequest req, StaplerResponse rsp, Object n

/**
* Creates a {@link RequestDispatcher} that forwards to the jelly view, if available.
*
* @deprecated removed without replacement
*/
@Deprecated
public RequestDispatcher createDispatcher(Object it, String viewName) throws IOException {
Expand Down
Loading

0 comments on commit 3605a77

Please sign in to comment.