Skip to content

Fix for type.getType(...) use on non-signature type names#221

Merged
garydgregory merged 8 commits intoapache:masterfrom
nbauma109:fix-for-Type.getType
Sep 15, 2023
Merged

Fix for type.getType(...) use on non-signature type names#221
garydgregory merged 8 commits intoapache:masterfrom
nbauma109:fix-for-Type.getType

Conversation

@nbauma109
Copy link
Copy Markdown
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
Copy Markdown

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

@garydgregory
Copy link
Copy Markdown
Member

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

@hazendaz
Copy link
Copy Markdown

@garydgregory Any status on this fix?

Copy link
Copy Markdown
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.


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
Copy Markdown
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
Copy Markdown
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

Copy link
Copy Markdown

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
Copy Markdown
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.

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sometime this week...

Copy link
Copy Markdown

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
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
Copy Markdown
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
Copy Markdown

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
@Jeeppler
Copy link
Copy Markdown

@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