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 silent NumberFormatException in SourceMapper #1834 #3543

Closed
wants to merge 1 commit into from

Conversation

jukzi
Copy link
Contributor

@jukzi jukzi commented Jan 9, 2025

@jukzi jukzi added bug Something isn't working performance labels Jan 9, 2025
@jukzi jukzi force-pushed the NumberFormatException branch from b03adc9 to 186b9b0 Compare January 9, 2025 10:05
@jukzi
Copy link
Contributor Author

jukzi commented Jan 9, 2025

List of tests where the change is executed:

 org.eclipse.jdt.core.tests.dom.ASTModelBridgeTests.testBinaryMemberTypeFromAnonymousClassFile1
 org.eclipse.jdt.core.tests.dom.ASTModelBridgeTests.testBinaryMemberTypeFromAnonymousClassFile2
 org.eclipse.jdt.core.tests.model.AttachSourceTests.testInnerClass2
 org.eclipse.jdt.core.tests.model.AttachSourceTests.testInnerClass3
 org.eclipse.jdt.core.tests.model.AttachSourceTests.testInnerClass4
 org.eclipse.jdt.core.tests.model.AttachSourceTests.testInnerClass7
 org.eclipse.jdt.core.tests.model.JavaSearchTests.testLocalVariableReference3
 org.eclipse.jdt.core.tests.model.ResolveTests.testLocalNameForClassFile
 org.eclipse.jdt.core.tests.model.ResolveTests.testMethodDeclarationInAnonymous4
 org.eclipse.jdt.core.tests.model.TypeResolveTests.testResolveTypeInBinary3

@jukzi jukzi force-pushed the NumberFormatException branch from 186b9b0 to 15e228a Compare January 9, 2025 11:36
@jukzi jukzi marked this pull request as ready for review January 9, 2025 11:37
@jukzi jukzi requested a review from stephan-herrmann January 9, 2025 11:37
@stephan-herrmann
Copy link
Contributor

Number-parsing part of the name of a classfile looks wrong, indeed, but let's dig a bit deeper:

  • while it's true that I made changes in this area via https://bugs.eclipse.org/521058 this didn't touch the case of anonymous classes, but only module-info.class
  • the block in question ..
  • the same https://bugs.eclipse.org/75885 also made SourceMapper.IType getType(String) fit for anonymous classes
  • given that the block in mapSource(NamedMember,char[],IBinaryType,IJavaElement) has been wrong for more than 20 years, what purpose would it serve anyway?
  • I couldn't find any test failing when I simply remove the block if (isAnonymousClass) 😄

So I suggest not to fix unnecessary code, but let's give @jarthana also a chance to chime in, if he has an idea what this code might be needed for.

@stephan-herrmann
Copy link
Contributor

One more observation: with or without the block in question, SourceMapper.anonymousClassName will always be 0.

Consider this block in enterType():

			this.anonymousCounter++;
			if (this.anonymousCounter == this.anonymousClassName) {
				this.types[this.typeDepth] = getType(this.binaryTypeOrModule.getElementName());
			} else {
				this.types[this.typeDepth] = getType(DeduplicationUtil.toString(typeInfo.name));
			}

if ananymousClassName is always 0, the then-branch of the above if will never be triggered, i.e., we always retrieve the type using an empty name. To check:

  • do we have tests challenging this code with more than one anonymous class (to be sure that int parsing is actually tested)?
  • does getType("") actually supersede (since bug 75885) the dead then-block?
  • perhaps we can completely remove field anonymousClassName and all code accessing it?

@jukzi
Copy link
Contributor Author

jukzi commented Jan 9, 2025

  • do we have tests challenging this code with more than one anonymous class (to be sure that int parsing is actually tested)?

AttachSourceTests.testInnerClass3 did evaluate the number to "2"

@jukzi jukzi force-pushed the NumberFormatException branch from 15e228a to 6998fbf Compare January 20, 2025 11:08
@jukzi
Copy link
Contributor Author

jukzi commented Jan 20, 2025

@stephan-herrmann what do we need to continue?

eclipse-jdt#1834

tested by
dom.ASTModelBridgeTests.testBinaryMemberTypeFromAnonymousClassFile1
dom.ASTModelBridgeTests.testBinaryMemberTypeFromAnonymousClassFile2
model.AttachSourceTests.testInnerClass2
model.AttachSourceTests.testInnerClass3
model.AttachSourceTests.testInnerClass4
model.AttachSourceTests.testInnerClass7
model.JavaSearchTests.testLocalVariableReference3
model.ResolveTests.testLocalNameForClassFile
model.ResolveTests.testMethodDeclarationInAnonymous4
model.TypeResolveTests.testResolveTypeInBinary3
@jukzi jukzi force-pushed the NumberFormatException branch from 6998fbf to ab65fa9 Compare January 20, 2025 13:24
@stephan-herrmann
Copy link
Contributor

@stephan-herrmann what do we need to continue?

Do we have any motivation to keep that code section?

See my hint:

perhaps we can completely remove field anonymousClassName and all code accessing it?

Debugging AttachSourceTests.testInnerClass3 I see the field used only to distinguish between using "" or "" as the classname :) -- The name of the classfile will always be determined inside getType().

@stephan-herrmann
Copy link
Contributor

perhaps we can completely remove field anonymousClassName and all code accessing it?

RunModelTests confirms my theory.

@jukzi
Copy link
Contributor Author

jukzi commented Jan 21, 2025

perhaps we can completely remove field anonymousClassName and all code accessing it?

I created a new PR for that: #3583

@jukzi jukzi closed this Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants