Skip to content
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

Merged
merged 8 commits into from
Sep 15, 2023

Conversation

nbauma109
Copy link
Contributor

This is a fix for a small regression introduced by PR #171 with the use of Type.getType(...) on an internal type name which needs to be converted to a signature first (i.e. java/lang/String => Ljava/lang/String;)

@JuditKnoll
Copy link

This fix seems to solve problem. It works on my machine.

@garydgregory
Copy link
Member

@JuditKnoll
Good to know. I'll take a look this weekend.

@hazendaz
Copy link

@garydgregory Any status on this fix?

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hazendaz @nbauma109
See my comment.

@@ -365,6 +366,24 @@ public int hashCode() {
return type ^ signature.hashCode();
}

static String internalTypeNameToSignature(final String internalTypeName) {
if (StringUtils.isEmpty(internalTypeName) || StringUtils.equalsAny(internalTypeName, "B", "C", "D", "F", "I", "J", "S", "Z")) {
return internalTypeName;
Copy link
Member

Choose a reason for hiding this comment

The 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 org.apache.bcel.generic.InstructionFactory.SHORT_NAMES (by making it public)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array has different values

Choose a reason for hiding this comment

The 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 Z, and J, but contains L additionally. The SHORT_TYPE_NAMES in Consts and Constants both contain V and ILLEGAL_TYPE unnecessarily. There are constants for the short names individually in ElementValue, but I'm not sure using those would help a lot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi all,
I'm looking for clarity when reading the code. A hard coded array of strings is bad. Having a good name for a constant would help, and SHORT_NAMES is not a good name when the class is Constants or Consts. Any improvement is appreciated.

Choose a reason for hiding this comment

The 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.
As far as I can see, this particular "array" contains the primitive or base types, but naming it is the privilege of the author.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garydgregory is it ok now ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garydgregory any chance you can have a look at it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometime this week...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garydgregory can you please look at this PR?

@nbauma109 nbauma109 requested a review from garydgregory August 29, 2023 20:01
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one! :-)

@codecov-commenter
Copy link

codecov-commenter commented Sep 15, 2023

Codecov Report

Merging #221 (c1e615d) into master (de3f858) will increase coverage by 0.02%.
Report is 64 commits behind head on master.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master     #221      +/-   ##
============================================
+ Coverage     64.73%   64.75%   +0.02%     
- Complexity     3872     3878       +6     
============================================
  Files           364      364              
  Lines         15666    15675       +9     
  Branches       1943     1946       +3     
============================================
+ Hits          10142    10151       +9     
  Misses         4602     4602              
  Partials        922      922              
Files Changed Coverage Δ
src/main/java/org/apache/bcel/Const.java 96.77% <ø> (ø)
src/main/java/org/apache/bcel/generic/LDC.java 80.85% <100.00%> (ø)
src/main/java/org/apache/bcel/generic/Type.java 85.80% <100.00%> (+0.77%) ⬆️

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@garydgregory garydgregory merged commit 87a5cae into apache:master Sep 15, 2023
13 checks passed
@Jeeppler
Copy link

@garydgregory thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants