You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by GitBox <gi...@apache.org> on 2020/08/15 12:34:54 UTC

[GitHub] [shiro] ddddyyyy opened a new pull request #248: [SHIRO-767] Fixed issue where ClassUtil cannot load the array of Primitive DataType...

ddddyyyy opened a new pull request #248:
URL: https://github.com/apache/shiro/pull/248


   ...when use undertown as web container


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shiro] ddddyyyy commented on a change in pull request #248: [SHIRO-767] Fixed issue where ClassUtil cannot load the array of Primitive DataType...

Posted by GitBox <gi...@apache.org>.
ddddyyyy commented on a change in pull request #248:
URL: https://github.com/apache/shiro/pull/248#discussion_r472569626



##########
File path: lang/src/main/java/org/apache/shiro/lang/util/ClassUtils.java
##########
@@ -252,7 +274,7 @@ public Class loadClass(String fqcn) {
             ClassLoader cl = getClassLoader();
             if (cl != null) {
                 try {
-                    clazz = cl.loadClass(fqcn);
+                    clazz = Class.forName(fqcn,false,cl);

Review comment:
       > Would you please add the whitespace? Then the code would be consistent again (whitespace after parameter comma). Thanks!
   
   OK.I have added whitespace in the latest commit.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shiro] fpapon merged pull request #248: [SHIRO-767] Fixed issue where ClassUtil cannot load the array of Primitive DataType...

Posted by GitBox <gi...@apache.org>.
fpapon merged pull request #248:
URL: https://github.com/apache/shiro/pull/248


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shiro] bmhm commented on a change in pull request #248: [SHIRO-767] Fixed issue where ClassUtil cannot load the array of Primitive DataType...

Posted by GitBox <gi...@apache.org>.
bmhm commented on a change in pull request #248:
URL: https://github.com/apache/shiro/pull/248#discussion_r471106943



##########
File path: lang/src/main/java/org/apache/shiro/lang/util/ClassUtils.java
##########
@@ -252,7 +274,7 @@ public Class loadClass(String fqcn) {
             ClassLoader cl = getClassLoader();
             if (cl != null) {
                 try {
-                    clazz = cl.loadClass(fqcn);
+                    clazz = Class.forName(fqcn,false,cl);

Review comment:
       I'd like to see spaces here and a comment why we changed this, e.g.
   // SHIRO-767: Use Class.forName instead of cl.loadClass(), as byte arrays would fail otherwise.

##########
File path: lang/src/main/test/java/org/apache/shiro/util/ClassUtilsTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.util;
+
+import org.apache.shiro.lang.util.ClassUtils;
+import org.apache.shiro.lang.util.UnknownClassException;
+import org.junit.Assert;
+import org.junit.Test;

Review comment:
       Writing new tests, we can use the Junit5 classes.

##########
File path: lang/src/main/test/java/org/apache/shiro/util/ClassUtilsTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.util;
+
+import org.apache.shiro.lang.util.ClassUtils;
+import org.apache.shiro.lang.util.UnknownClassException;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class ClassUtilsTest {
+
+    @Test
+    public void testGetPrimitiveClasses() throws UnknownClassException {
+
+        Assert.assertEquals(ClassUtils.forName("boolean"), boolean.class);
+        Assert.assertEquals(ClassUtils.forName("byte"), byte.class);
+        Assert.assertEquals(ClassUtils.forName("char"), char.class);
+        Assert.assertEquals(ClassUtils.forName("short"), short.class);
+        Assert.assertEquals(ClassUtils.forName("int"), int.class);
+        Assert.assertEquals(ClassUtils.forName("long"), long.class);
+        Assert.assertEquals(ClassUtils.forName("float"), float.class);
+        Assert.assertEquals(ClassUtils.forName("double"), double.class);
+        Assert.assertEquals(ClassUtils.forName("void"), void.class);
+
+        Assert.assertEquals(ClassUtils.forName(boolean.class.getName()), boolean.class);
+        Assert.assertEquals(ClassUtils.forName(byte.class.getName()), byte.class);
+        Assert.assertEquals(ClassUtils.forName(char.class.getName()), char.class);
+        Assert.assertEquals(ClassUtils.forName(short.class.getName()), short.class);
+        Assert.assertEquals(ClassUtils.forName(int.class.getName()), int.class);
+        Assert.assertEquals(ClassUtils.forName(long.class.getName()), long.class);
+        Assert.assertEquals(ClassUtils.forName(float.class.getName()), float.class);
+        Assert.assertEquals(ClassUtils.forName(double.class.getName()), double.class);
+        Assert.assertEquals(ClassUtils.forName(void.class.getName()), void.class);
+
+    }
+
+    @Test
+    public void testGetPrimitiveArrays() throws UnknownClassException {
+
+        Assert.assertEquals(ClassUtils.forName("[Z"), boolean[].class);
+        Assert.assertEquals(ClassUtils.forName("[B"), byte[].class);
+        Assert.assertEquals(ClassUtils.forName("[C"), char[].class);
+        Assert.assertEquals(ClassUtils.forName("[S"), short[].class);
+        Assert.assertEquals(ClassUtils.forName("[I"), int[].class);
+        Assert.assertEquals(ClassUtils.forName("[J"), long[].class);
+        Assert.assertEquals(ClassUtils.forName("[F"), float[].class);
+        Assert.assertEquals(ClassUtils.forName("[D"), double[].class);
+
+
+        Assert.assertEquals(ClassUtils.forName(boolean[].class.getName()), boolean[].class);
+        Assert.assertEquals(ClassUtils.forName(byte[].class.getName()), byte[].class);
+        Assert.assertEquals(ClassUtils.forName(char[].class.getName()), char[].class);
+        Assert.assertEquals(ClassUtils.forName(short[].class.getName()), short[].class);
+        Assert.assertEquals(ClassUtils.forName(int[].class.getName()), int[].class);
+        Assert.assertEquals(ClassUtils.forName(long[].class.getName()), long[].class);
+        Assert.assertEquals(ClassUtils.forName(float[].class.getName()), float[].class);
+        Assert.assertEquals(ClassUtils.forName(double[].class.getName()), double[].class);
+    }
+
+    @Test
+    public void testGetClass() {
+        Assert.assertEquals(ClassUtils.forName("java.lang.String"), String.class);
+        Assert.assertEquals(ClassUtils.forName("[Ljava.lang.String;"), String[].class);
+        Assert.assertEquals(ClassUtils.forName(String.class.getName()), String.class);
+        Assert.assertEquals(ClassUtils.forName(String[].class.getName()), String[].class);
+
+        Assert.assertEquals(ClassUtils.forName("org.apache.shiro.util.ClassUtilsTest"), ClassUtilsTest.class);
+        Assert.assertEquals(ClassUtils.forName("[Lorg.apache.shiro.util.ClassUtilsTest;"), ClassUtilsTest[].class);

Review comment:
       When put into the correct path and package, this test will fail:
   `org.apache.shiro.lang.util.UnknownClassException: Unable to load class named [[Lorg.apache.shiro.util.ClassUtilsTest;] from the thread context, current, or system/application ClassLoaders.  All heuristics have been exhausted.  Class could not be found.`

##########
File path: lang/src/main/test/java/org/apache/shiro/util/ClassUtilsTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.util;

Review comment:
       It is also in the wrong package. `lang` is correct, but you used `util`.

##########
File path: lang/src/main/test/java/org/apache/shiro/util/ClassUtilsTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.util;

Review comment:
       The class is in the wrong directory. It is `lang/src/main/test/java` but you meant `lang/src/test/java`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shiro] bmhm commented on a change in pull request #248: [SHIRO-767] Fixed issue where ClassUtil cannot load the array of Primitive DataType...

Posted by GitBox <gi...@apache.org>.
bmhm commented on a change in pull request #248:
URL: https://github.com/apache/shiro/pull/248#discussion_r472433114



##########
File path: lang/src/main/java/org/apache/shiro/lang/util/ClassUtils.java
##########
@@ -252,7 +274,7 @@ public Class loadClass(String fqcn) {
             ClassLoader cl = getClassLoader();
             if (cl != null) {
                 try {
-                    clazz = cl.loadClass(fqcn);
+                    clazz = Class.forName(fqcn,false,cl);

Review comment:
       Would you please add the whitespace? Then the code would be consistent again (whitespace after parameter comma). Thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org