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

Fixes #3215 - ClassFileWorkingCopy.getFileName() does not follow API doc #3216

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

robstryker
Copy link
Contributor

See #3215

What it does

How to test

Author checklist

String parentPath = this.classFile.getParent().getPath().toString();
IPackageFragment enclosingPackage = (IPackageFragment)getAncestor(IJavaElement.PACKAGE_FRAGMENT);
String pack = enclosingPackage == null ? "" : enclosingPackage.getElementName();
String packReplaced = pack.length() > 0 ? pack.replaceAll("\\.", "/") + "/" : "";
Copy link
Contributor

Choose a reason for hiding this comment

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

where do you see a requirement to use a specific separator?

Copy link
Contributor Author

@robstryker robstryker Nov 2, 2024

Choose a reason for hiding this comment

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

The documentation for IDependent.getFileName();

In summary, the two examples provided are:

 *  "c:\\lib\\some.jar|/com/p/X.class" or
 *  "/lib/some.zip|/com/q/Y.class".

It uses a system path separator for the resource, followed by the jar separator, followed by the package with forward slashes only for both major operating systems.

/**
 * Answer the file name which defines the type.
 *
 * The path part (optional) must be separated from the actual
 * file proper name by a separator suitable for the type (java.io.File.separator for example),
 * e.g.
 *  "c:\\source\\com\\p\\X.java" or
 *  "/com/p/Y.java".
 *
 * The path to the zip or jar file (optional) must be separated
 * from the actual path part by JAR_FILE_ENTRY_SEPARATOR,
 * e.g.
 *  "c:\\lib\\some.jar|/com/p/X.class" or
 *  "/lib/some.zip|/com/q/Y.class".
 *
 * The proper file name includes the suffix extension (e.g. ".java")
 * e.g. "c:/org/eclipse/jdt/internal/compileri/env/IDependent.java"
 *
 * Return null if no file defines the type.
 */

char[] getFileName();

Comment on lines +1006 to +1008
if( root == null ) {
root = getJarPkgFragmentRoot(new String(fileName), jarSeparator, jarMemento);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what motivates this change in a PR addressing a problem in ClassFileWorkingCopy?

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 tests continued to fail will the following stacktrace. I realize this will be impossible to actually follow, as you don't have our underlying implementations. I could try to break this part out and come up with a new specific test. But anyway, here goes:

Util.getPackageFragment(char[], int, int) line: 1011	
Util.getClassFile(char[]) line: 810	
Util.getUnresolvedJavaElement(TypeBinding, WorkingCopyOwner, Util$BindingsToNodesMap) line: 1611	
TypeBinding.getUnresolvedJavaElement(TypeBinding) line: 566	
TypeBinding.getUnresolvedJavaElement() line: 557	
TypeBinding.getJavaElement() line: 539	

getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator) appears to be set up to handle inside-jar paths, but, for some reason, it wasn't working for me. In this case, the values passed in were:

fileName=/home/rob/apps/eclipse/workspaces/jclMin1.8.jar|java/lang/RuntimeException.class
pkgEnd=57
jarSeparator=47

The call to PackageFragmentRoot root = (PackageFragmentRoot) JavaCore.create(jarMemento); was returning null when jarMemento has a value of /home/rob/apps/eclipse/workspaces/jclMin1.8.jar

I'm not familiar enough with this code to know why it's doing things this way. It appears to me that the currently implementation simply did not function for this specific case. But I did know i had browsed similar code that did properly turn a path of this structure into a PackageFragmentRoot without error, and so I copied it over, and it worked.

I still maintain that this change to locating the PackageFragmentRoot is at the very least closely related to changing the getFileName() implementation from returning the path of the jar to the full path of the resource inside the jar. If you prefer, I can try to break this specific issue out and try to develop a test case for it.

@robstryker
Copy link
Contributor Author

The most recent build of this PR still has 2 failures, but I am unable to replicate those failures locally :|

@robstryker
Copy link
Contributor Author

The two failing tests are not replicatable locally.

Breakpoints set at the following locations:
ClassFileWorkingCopy [line: 88] - getFileName()
CompilationUnit [line: 243] - getFileName()
Util [line: 1007] - getPackageFragment(char[], int, int)

Only the breakpoint at CompilationUnit.getFileName() appears to be hit in these two tests, however, the new implementation appears to return the exact same results as the superclass / previous results. So I'm really not sure what could be happening here.

Any advice is appreciated.

@robstryker
Copy link
Contributor Author

I really believe this issue is worth looking at, though, because the current code is out of spec with its own documentation. With only two failures (that I can't replicate locally), I think it's unlikely these changes have significantly altered the code or results, especially since the two failing tests don't even seem to enter any of the changes I've made except 1.

@robstryker robstryker force-pushed the ClassFile_getFileName branch from f395ece to ed17354 Compare December 5, 2024 15:26
Rob Stryker added 2 commits December 10, 2024 09:34
…follow API doc

Signed-off-by: Rob Stryker <stryker@redhat.com>
Signed-off-by: Rob Stryker <stryker@redhat.com>

Fix test case

Signed-off-by: Rob Stryker <stryker@redhat.com>
@robstryker robstryker force-pushed the ClassFile_getFileName branch from ed17354 to b75f2dc Compare December 10, 2024 14:34
@robstryker
Copy link
Contributor Author

Is anyone else able to reproduce the 3 failures? I can't reproduce them on my local machine.

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.

2 participants