-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for type.getType(...) use on non-signature type names #221
Changes from 7 commits
4816a0f
c25de87
8fd3efd
e8f89f0
8ad6cc4
19121c0
c1e615d
7baad01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import org.apache.bcel.classfile.ClassFormatException; | ||
import org.apache.bcel.classfile.InvalidMethodSignatureException; | ||
import org.apache.bcel.classfile.Utility; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** | ||
* Abstract super class for all possible java types, namely basic types such as int, object types like String and array | ||
|
@@ -180,7 +181,7 @@ public static String getSignature(final java.lang.reflect.Method meth) { | |
public static Type getType(final Class<?> cls) { | ||
Objects.requireNonNull(cls, "cls"); | ||
/* | ||
* That's an amzingly easy case, because getName() returns the signature. That's what we would have liked anyway. | ||
* That's an amazingly easy case, because getName() returns the signature. That's what we would have liked anyway. | ||
*/ | ||
if (cls.isArray()) { | ||
return getType(cls.getName()); | ||
|
@@ -365,6 +366,24 @@ public int hashCode() { | |
return type ^ signature.hashCode(); | ||
} | ||
|
||
static String internalTypeNameToSignature(final String internalTypeName) { | ||
if (StringUtils.isEmpty(internalTypeName) || StringUtils.equalsAny(internalTypeName, Const.SHORT_TYPE_NAMES)) { | ||
return internalTypeName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not crazy about this magic list of strings. Could we reuse or refactor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The array has different values There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find any array containing these exact short names. The mentioned SHORT_NAMES misses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi all, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since none of the existing arrays could be reused here because of the different values, the renaming should be in a separate PR, not in this one. In the JVM specification these short names are introduced as field descriptors, but that name may cause some confusion with the field and it rather refers to the type of the fields. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. InstructionFactory.SHORT_NAMES wasn't a good fit but Const.SHORT_TYPE_NAMES looks better suited There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @garydgregory is it ok now ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @garydgregory any chance you can have a look at it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometime this week... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @garydgregory can you please look at this PR? |
||
} | ||
switch(internalTypeName.charAt(0)) { | ||
case '[': | ||
return internalTypeName; | ||
case 'L': | ||
case 'T': | ||
if (internalTypeName.charAt(internalTypeName.length() - 1) == ';') { | ||
return internalTypeName; | ||
} | ||
return 'L' + internalTypeName + ';'; | ||
default: | ||
return 'L' + internalTypeName + ';'; | ||
} | ||
} | ||
|
||
/** | ||
* boolean, short and char variable are considered as int in the stack or local variable area. Returns {@link Type#INT} | ||
* for {@link Type#BOOLEAN}, {@link Type#SHORT} or {@link Type#CHAR}, otherwise returns the given type. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good one! :-)