From c8a8c2b1da03730b288898c7feb1c3b205c506e8 Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Mon, 6 Feb 2023 21:07:18 +0200 Subject: [PATCH] Move to Java 11 (#629) --- .../src/test/java/ro/pippo/jaxb/JaxbEngineTest.java | 4 ++-- .../src/main/java/ro/pippo/core/Application.java | 2 +- .../main/java/ro/pippo/core/ContentTypeEngines.java | 2 +- .../src/main/java/ro/pippo/core/ParameterValue.java | 4 ++-- pippo-core/src/main/java/ro/pippo/core/Pippo.java | 4 ++-- .../src/main/java/ro/pippo/core/PippoFilter.java | 2 +- .../src/main/java/ro/pippo/core/PippoServlet.java | 2 +- .../core/entity/DefaultEntityRequestEngine.java | 2 +- .../java/ro/pippo/core/reload/ReloadClassLoader.java | 2 +- .../java/ro/pippo/pac4j/PippoSessionStoreTest.java | 9 ++++++--- .../java/ro/pippo/pac4j/PippoWebContextTest.java | 12 ++++++++---- .../src/main/java/ro/pippo/jetty/JettyServer.java | 8 ++++---- pom.xml | 6 ++---- 13 files changed, 32 insertions(+), 27 deletions(-) diff --git a/pippo-content-type-parent/pippo-jaxb/src/test/java/ro/pippo/jaxb/JaxbEngineTest.java b/pippo-content-type-parent/pippo-jaxb/src/test/java/ro/pippo/jaxb/JaxbEngineTest.java index 61fecc94..892da14e 100644 --- a/pippo-content-type-parent/pippo-jaxb/src/test/java/ro/pippo/jaxb/JaxbEngineTest.java +++ b/pippo-content-type-parent/pippo-jaxb/src/test/java/ro/pippo/jaxb/JaxbEngineTest.java @@ -33,7 +33,7 @@ import org.junit.rules.TestWatcher; import org.junit.runner.Description; -import com.sun.org.apache.xerces.internal.impl.Constants; +//import com.sun.org.apache.xerces.internal.impl.Constants; import ro.pippo.core.PippoRuntimeException; import ro.pippo.core.util.IoUtils; @@ -57,7 +57,7 @@ public void setUp() { jaxbEngine = new JaxbEngine(); // JDK property to allow printing out information from the limit analyzer - jaxbEngine.setProperty(Constants.JDK_ENTITY_COUNT_INFO, "yes"); +// jaxbEngine.setProperty(Constants.JDK_ENTITY_COUNT_INFO, "yes"); } @Test diff --git a/pippo-core/src/main/java/ro/pippo/core/Application.java b/pippo-core/src/main/java/ro/pippo/core/Application.java index 930eaa58..052400ab 100644 --- a/pippo-core/src/main/java/ro/pippo/core/Application.java +++ b/pippo-core/src/main/java/ro/pippo/core/Application.java @@ -186,7 +186,7 @@ public void registerTemplateEngine(Class engineClass) } try { - TemplateEngine engine = engineClass.newInstance(); + TemplateEngine engine = engineClass.getDeclaredConstructor().newInstance(); setTemplateEngine(engine); } catch (Exception e) { throw new PippoRuntimeException(e, "Failed to instantiate '{}'", engineClass.getName()); diff --git a/pippo-core/src/main/java/ro/pippo/core/ContentTypeEngines.java b/pippo-core/src/main/java/ro/pippo/core/ContentTypeEngines.java index a0b0367d..d9efa854 100644 --- a/pippo-core/src/main/java/ro/pippo/core/ContentTypeEngines.java +++ b/pippo-core/src/main/java/ro/pippo/core/ContentTypeEngines.java @@ -91,7 +91,7 @@ public List getContentTypeSuffixes() { public ContentTypeEngine registerContentTypeEngine(Class engineClass) { ContentTypeEngine engine; try { - engine = engineClass.newInstance(); + engine = engineClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new PippoRuntimeException(e, "Failed to instantiate '{}'", engineClass.getName()); } diff --git a/pippo-core/src/main/java/ro/pippo/core/ParameterValue.java b/pippo-core/src/main/java/ro/pippo/core/ParameterValue.java index 6a873171..4e567ba3 100644 --- a/pippo-core/src/main/java/ro/pippo/core/ParameterValue.java +++ b/pippo-core/src/main/java/ro/pippo/core/ParameterValue.java @@ -423,9 +423,9 @@ public T to(Class classOfT, String pattern) { public > T convert(Class converterClass, String pattern) { try { - C converter = converterClass.newInstance(); + C converter = converterClass.getDeclaredConstructor().newInstance(); return converter.getAsObject(values, locale, pattern); - } catch (InstantiationException | IllegalAccessException e) { + } catch (Exception e) { throw new PippoRuntimeException(e, "Failed to convert"); } } diff --git a/pippo-core/src/main/java/ro/pippo/core/Pippo.java b/pippo-core/src/main/java/ro/pippo/core/Pippo.java index c991c52a..beb5af04 100644 --- a/pippo-core/src/main/java/ro/pippo/core/Pippo.java +++ b/pippo-core/src/main/java/ro/pippo/core/Pippo.java @@ -306,8 +306,8 @@ protected Application createReloadableApplication(ClassLoader classLoader) { try { Class applicationClass = classLoader.loadClass(applicationClassName); - application = (Application) applicationClass.newInstance(); - } catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) { + application = (Application) applicationClass.getDeclaredConstructor().newInstance(); + } catch (Exception e) { throw new PippoRuntimeException(e); } diff --git a/pippo-core/src/main/java/ro/pippo/core/PippoFilter.java b/pippo-core/src/main/java/ro/pippo/core/PippoFilter.java index 9c4dceb1..db5ed6df 100644 --- a/pippo-core/src/main/java/ro/pippo/core/PippoFilter.java +++ b/pippo-core/src/main/java/ro/pippo/core/PippoFilter.java @@ -265,7 +265,7 @@ protected void createApplication(FilterConfig filterConfig) throws ServletExcept try { Class applicationClass = Class.forName(applicationClassName); - application = (Application) applicationClass.newInstance(); + application = (Application) applicationClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { log.error("Cannot create application with className '{}'", applicationClassName, e); throw new ServletException(e); diff --git a/pippo-core/src/main/java/ro/pippo/core/PippoServlet.java b/pippo-core/src/main/java/ro/pippo/core/PippoServlet.java index 896663f6..f1c99ae5 100644 --- a/pippo-core/src/main/java/ro/pippo/core/PippoServlet.java +++ b/pippo-core/src/main/java/ro/pippo/core/PippoServlet.java @@ -155,7 +155,7 @@ private void createApplication(ServletConfig servletConfig) { try { Class applicationClass = Class.forName(applicationClassName); - application = (Application) applicationClass.newInstance(); + application = (Application) applicationClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { log.error("Cannot create application with className '{}'", applicationClassName, e); throw new PippoRuntimeException(e); diff --git a/pippo-core/src/main/java/ro/pippo/core/entity/DefaultEntityRequestEngine.java b/pippo-core/src/main/java/ro/pippo/core/entity/DefaultEntityRequestEngine.java index be0ab49f..02ba0c40 100644 --- a/pippo-core/src/main/java/ro/pippo/core/entity/DefaultEntityRequestEngine.java +++ b/pippo-core/src/main/java/ro/pippo/core/entity/DefaultEntityRequestEngine.java @@ -52,7 +52,7 @@ public DefaultEntityRequestEngine(ContentTypeEngines contentTypeEngines) { public T createEntityFromParameters(Class entityClass, Request request) { T entity; try { - entity = entityClass.newInstance(); + entity = entityClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { log.error("Cannot create new instance of class '{}'", entityClass.getName(), e); return null; diff --git a/pippo-core/src/main/java/ro/pippo/core/reload/ReloadClassLoader.java b/pippo-core/src/main/java/ro/pippo/core/reload/ReloadClassLoader.java index 0571fdbc..670b3b12 100644 --- a/pippo-core/src/main/java/ro/pippo/core/reload/ReloadClassLoader.java +++ b/pippo-core/src/main/java/ro/pippo/core/reload/ReloadClassLoader.java @@ -59,7 +59,7 @@ public Class loadClass(String className, boolean resolve) throws ClassNotFoun int index = className.lastIndexOf('.'); if (index >= 0) { String packageName = className.substring(0, index); - if (getPackage(packageName) == null) { + if (getDefinedPackage(packageName) == null) { try { definePackage(packageName, null, null, null, null, null, null, null); } catch (IllegalArgumentException e) { diff --git a/pippo-security-parent/pippo-pac4j/src/test/java/ro/pippo/pac4j/PippoSessionStoreTest.java b/pippo-security-parent/pippo-pac4j/src/test/java/ro/pippo/pac4j/PippoSessionStoreTest.java index fbbb7770..d2705d9e 100644 --- a/pippo-security-parent/pippo-pac4j/src/test/java/ro/pippo/pac4j/PippoSessionStoreTest.java +++ b/pippo-security-parent/pippo-pac4j/src/test/java/ro/pippo/pac4j/PippoSessionStoreTest.java @@ -18,14 +18,17 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import ro.pippo.core.Session; import ro.pippo.core.route.RouteContext; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNull.nullValue; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * @author Ranganath Kini diff --git a/pippo-security-parent/pippo-pac4j/src/test/java/ro/pippo/pac4j/PippoWebContextTest.java b/pippo-security-parent/pippo-pac4j/src/test/java/ro/pippo/pac4j/PippoWebContextTest.java index 4da3e11a..9f239478 100644 --- a/pippo-security-parent/pippo-pac4j/src/test/java/ro/pippo/pac4j/PippoWebContextTest.java +++ b/pippo-security-parent/pippo-pac4j/src/test/java/ro/pippo/pac4j/PippoWebContextTest.java @@ -22,7 +22,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.pac4j.core.context.Cookie; import org.pac4j.core.context.session.SessionStore; import ro.pippo.core.Application; @@ -43,9 +43,13 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * @author Ranganath Kini diff --git a/pippo-server-parent/pippo-jetty/src/main/java/ro/pippo/jetty/JettyServer.java b/pippo-server-parent/pippo-jetty/src/main/java/ro/pippo/jetty/JettyServer.java index 6b4604f4..4b57dcc2 100644 --- a/pippo-server-parent/pippo-jetty/src/main/java/ro/pippo/jetty/JettyServer.java +++ b/pippo-server-parent/pippo-jetty/src/main/java/ro/pippo/jetty/JettyServer.java @@ -194,8 +194,8 @@ protected ServletContextHandler createPippoHandler() { // all listeners listeners.forEach(listener -> { try { - handler.addEventListener(listener.newInstance()); - } catch (InstantiationException | IllegalAccessException e) { + handler.addEventListener(listener.getDeclaredConstructor().newInstance()); + } catch (Exception e) { throw new PippoRuntimeException(e); } }); @@ -221,8 +221,8 @@ protected PippoFilter createPippoFilter() { try { // create an instance of JettyWebSocketFilter Class pippoFilterClass = Class.forName("ro.pippo.jetty.websocket.JettyWebSocketFilter"); - return (PippoFilter) pippoFilterClass.newInstance(); - } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { + return (PippoFilter) pippoFilterClass.getDeclaredConstructor().newInstance(); + } catch (Exception e) { throw new PippoRuntimeException(e); } } diff --git a/pom.xml b/pom.xml index 0ae669f6..b14b6779 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ UTF-8 - 1.8 + 11 2.3.1 2.3.0.1 @@ -53,7 +53,7 @@ 4.0.2 4.13 - 2.24.0 + 5.1.1 @@ -63,8 +63,6 @@ maven-compiler-plugin 3.8.0 - ${java.version} - ${java.version} UTF-8 true true