Skip to content

Commit

Permalink
Fixes #4023 - Fix build warnings (#4024)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem authored Sep 27, 2024
1 parent cd51533 commit 568a819
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ public class ManagedPiranhaContainerConfiguration implements ContainerConfigurat
*/
private boolean suspend = Boolean.parseBoolean(System.getProperty("piranha.suspend", "false"));

/**
* Constructor.
*/
public ManagedPiranhaContainerConfiguration() {
}

/**
* Get the HTTP port.
*
Expand Down Expand Up @@ -138,6 +144,33 @@ public String getProtocol() {
return protocol;
}

/**
* Is the debug flag set.
*
* @return true if it is, false otherwise.
*/
public boolean isDebug() {
return debug;
}

/**
* Is the suspend flag set.
*
* @return the suspend flag.
*/
public boolean isSuspend() {
return suspend;
}

/**
* Set the debug flag.
*
* @param debug the debug flag.
*/
public void setDebug(boolean debug) {
this.debug = debug;
}

/**
* Set the HTTP port.
*
Expand Down Expand Up @@ -165,36 +198,9 @@ public void setProtocol(String protocol) {
this.protocol = protocol;
}

/**
* Is the debug flag set?
*
* @return true if the debug flag is set, false otherwise.
*/
public boolean isDebug() {
return debug;
}

/**
* Set the debug flag.
*
* @param debug the debug flag.
*/
public void setDebug(boolean debug) {
this.debug = debug;
}

/**
* Is the suspend flag set?
*
* @return true if the suspend flag is set, false otherwise.
*/
public boolean isSuspend() {
return suspend;
}

/**
* Set the suspend flag.
*
*
* @param suspend the suspend flag.
*/
public void setSuspend(boolean suspend) {
Expand Down
6 changes: 6 additions & 0 deletions cli/cli/src/main/java/cloud/piranha/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public class Cli {
* Stores the arguments.
*/
private String[] arguments;

/**
* Constructor.
*/
public Cli() {
}

/**
* Main method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public interface WebApplicationResponse extends HttpServletResponse {

/**
* Get the content length.
*
* @return the content length.
*/
long getContentLength();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public class WebXmlFilter {
*/
private String servletName;

/**
* Constructor.
*/
public WebXmlFilter() {
}

/**
* Add init param.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public class WebXmlSecurityConstraint {
*/
private List<WebResourceCollection> webResourceCollections = new ArrayList<>();

/**
* Constructor.
*/
public WebXmlSecurityConstraint() {
}

/**
* Get the role names.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ public class CookieParser {
*/
private static final String VERSION = "$Version=";

private CookieParser() {}
private CookieParser() {
}

/**
* Parse the Cookie header
*
* @param cookieValues the Cookie header, without "Cookie:"
* @return the {@link Cookie} array
* @throws NullPointerException if cookieValues is null
* @throws IllegalArgumentException if some cookie contains a illegal character
* @throws IllegalArgumentException if some cookie contains a illegal
* character
*/
public static Cookie[] parse(String cookieValues) {
Objects.requireNonNull(cookieValues);
Expand Down Expand Up @@ -77,6 +80,7 @@ private static Cookie[] parseNetscape(String cookiesValue) {
return cookieList.toArray(new Cookie[0]);
}

@SuppressWarnings({"deprecation", "removal"})
private static Cookie[] parseRFC2109(String cookiesValue) {
List<Cookie> cookieList = new ArrayList<>();
String[] cookieCandidates = cookiesValue.split("[;,]");
Expand All @@ -87,10 +91,10 @@ private static Cookie[] parseRFC2109(String cookiesValue) {
String name = removeQuotes(values[0].trim());
String value = values.length == 2 ? removeQuotes(values[1].trim()) : null;


if (name.startsWith("$")) {
if (currentCookie == null)
if (currentCookie == null) {
throw new IllegalArgumentException("Invalid Cookie");
}

if ("$Domain".equals(name)) {
currentCookie.setDomain(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public String changeSessionId(HttpServletRequest request) {
}

@Override
@SuppressWarnings({"deprecation", "removal"})
public synchronized HttpSession createSession(HttpServletRequest request) {
String sessionId = UUID.randomUUID().toString();
DefaultHttpSession session = new DefaultHttpSession(webApplication, sessionId, true);
Expand Down Expand Up @@ -287,6 +288,7 @@ public String encodeURL(HttpServletResponse response, String url) {
}

@Override
@SuppressWarnings({"deprecation", "removal"})
public String getComment() {
return comment;
}
Expand Down Expand Up @@ -380,6 +382,7 @@ protected void reapSessions() {
}

@Override
@SuppressWarnings({"deprecation", "removal"})
public void setComment(String comment) {
if (webApplication.isInitialized()) {
throw new IllegalStateException("You cannot call setComment once ServletContext is initialized");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ private void writeContentType() throws IOException {
* @param cookie the cookie.
* @throws IOException when an I/O error occurs.
*/
@SuppressWarnings({"deprecation", "removal"})
private void writeCookie(Cookie cookie) throws IOException {
outputStream.write("Set-Cookie: ".getBytes());
outputStream.write(cookie.getName().getBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CookieParserTest {

/*
REVIEW FOR SERVLET 6
TODO - REVIEW FOR SERVLET 6
@Nested
class RFC2109 {
Expand Down Expand Up @@ -75,6 +75,7 @@ void parseMultipleCookies() {
*/

@Nested
@SuppressWarnings({"deprecation", "removal"})
class Netscape {
@Test
void parseSingleCookie() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ void testGetAttributeNames() {
/**
* Test getCookies method.
*/
@SuppressWarnings({"deprecation", "removal"})
@Test
void testGetCookies() {
DefaultWebApplication webApplication = new DefaultWebApplication();
Expand Down Expand Up @@ -601,6 +602,7 @@ void testSetMaxInactiveInterval() {
*/
public static class TestSetCommentListener implements ServletContextListener {

@SuppressWarnings({"deprecation", "removal"})
@Override
public void contextInitialized(ServletContextEvent event) {
event.getServletContext().getSessionCookieConfig().setComment("MY COMMENT");
Expand All @@ -613,6 +615,7 @@ public void contextInitialized(ServletContextEvent event) {
*/
public static class TestSetCommentServlet extends HttpServlet {

@SuppressWarnings({"deprecation", "removal"})
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Expand Down Expand Up @@ -821,6 +824,7 @@ void testIsSecure() {
*
* @throws Exception when a serious error occurs.
*/
@SuppressWarnings({"deprecation", "removal"})
@Test
void testSetComment() throws Exception {
DefaultWebApplication webApplication = new DefaultWebApplication();
Expand All @@ -832,6 +836,7 @@ void testSetComment() throws Exception {
/**
* Test setComment.
*/
@SuppressWarnings({"deprecation", "removal"})
@Test
void testSetComment2() throws Exception {
DefaultWebApplication webApplication = new DefaultWebApplication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public class DefaultHttpServerProcessor implements HttpServerProcessor {
private static final String IO_ERROR_WRITING_RESPONSE =
"An I/O error occurred while writing the response";

/**
* Constructor.
*/
public DefaultHttpServerProcessor() {
}

@Override
public HttpServerProcessorEndState process(HttpServerRequest request, HttpServerResponse response) {
response.setStatus(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public abstract class HttpServerTest {
*/
private static final String TEXT_PLAIN = "text/plain";

/**
* Constructor.
*/
public HttpServerTest() {
}

/**
* Create server with a port.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public class TestHttpServerProcessor implements HttpServerProcessor {
private static final String IO_ERROR_WRITING_RESPONSE =
"An I/O error occurred while writing the response";

/**
* Constructor.
*/
public TestHttpServerProcessor() {
}

@Override
public HttpServerProcessorEndState process(HttpServerRequest request, HttpServerResponse response) {
response.setStatus(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ public abstract class BaseMojo extends AbstractMojo {
protected String warName;

/**
* Default constructor.
* Constructor.
*/
public BaseMojo() {
}

/**
* Convert a Maven groupId to a path snippet.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
public class RunMojo extends BaseMojo {

/**
* Default constructor.
* Constructor.
*/
public RunMojo() {
}

@Override
public void execute() throws MojoExecutionException {
if (!skip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,29 @@ public class StopMojo extends AbstractMojo {
private boolean skip;

/**
* Default constructor.
* Constructor.
*/
public StopMojo() {
}

@Override
public void execute() throws MojoExecutionException {
if (!skip) {
try {
/*
* Get the PID from the PID file.
*/
String pid = Files.readString((new File(
runtimeDirectory, "tmp/piranha.pid").toPath()));
File pidFile = new File(runtimeDirectory, "tmp/piranha.pid");
String pid = "";

if (pidFile.exists()) {
pid = Files.readString(pidFile.toPath());
}

/*
* Delete the PID file.
*/
if (!Files.deleteIfExists(new File(
runtimeDirectory, "tmp/piranha.pid").toPath())) {
if (!Files.deleteIfExists(pidFile.toPath())) {
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException ex) {
Expand Down

0 comments on commit 568a819

Please sign in to comment.