You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2020/12/10 07:01:11 UTC

[wicket] branch master updated: Fix gettting the 'modifiers' field for Java 12+

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new 668aaac  Fix gettting the 'modifiers' field for Java 12+
668aaac is described below

commit 668aaac86b5f7b9adf2ddf13231c50d638dcac59
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Thu Dec 10 09:00:29 2020 +0200

    Fix gettting the 'modifiers' field for Java 12+
    
    Remove unused method.
---
 .../org/apache/wicket/util/string/StringsTest.java | 40 +++++++++++++++++-----
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/wicket-util/src/test/java/org/apache/wicket/util/string/StringsTest.java b/wicket-util/src/test/java/org/apache/wicket/util/string/StringsTest.java
index 3a0ce9a..10bb526 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/string/StringsTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/string/StringsTest.java
@@ -23,16 +23,15 @@ import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.Arrays;
 import java.util.List;
 
 import org.junit.jupiter.api.Test;
 
-@SuppressWarnings("javadoc")
-public class StringsTest
+class StringsTest
 {
 	@Test
 	void stripJSessionId() throws Exception
@@ -56,7 +55,7 @@ public class StringsTest
 		// WICKET-6858
 		final Field sessionIdParamField = Strings.class.getDeclaredField("SESSION_ID_PARAM");
 		sessionIdParamField.setAccessible(true);
-		Field modifiersField = Field.class.getDeclaredField( "modifiers");
+		Field modifiersField = getModifiersField();
 		modifiersField.setAccessible(true);
 		try {
 			final String customSessionIdParam = ";Custom seSsion - ид=";
@@ -72,6 +71,34 @@ public class StringsTest
 		}
 	}
 
+	private Field getModifiersField() throws NoSuchFieldException
+	{
+		try
+		{
+			return Field.class.getDeclaredField("modifiers");
+		}
+		catch (NoSuchFieldException e) {
+			try
+			{
+				Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
+				getDeclaredFields0.setAccessible(true);
+				Field[] fields = (Field[]) getDeclaredFields0.invoke(Field.class, false);
+				for (Field field : fields)
+				{
+					if ("modifiers".equals(field.getName()))
+					{
+						return field;
+					}
+				}
+			}
+			catch (ReflectiveOperationException ex)
+			{
+				e.addSuppressed(ex);
+			}
+			throw e;
+		}
+	}
+
 	@Test
 	void test()
 	{
@@ -231,11 +258,6 @@ public class StringsTest
 				"&#199;&#252;&#233;&#226;&#228;&#224;&#229;&#231;&#234;&#235;"));
 	}
 
-	private String convertNonASCIIString(final String str) throws UnsupportedEncodingException
-	{
-		return new String(str.getBytes(), "iso-8859-1");
-	}
-
 	@Test
 	void firstPathComponent()
 	{