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

DirectoryChooserUI: reduce reflective win ShellFolder API usage #8110

Merged
merged 1 commit into from
Jan 5, 2025

Conversation

mbien
Copy link
Member

@mbien mbien commented Jan 3, 2025

  • some internal methods are now public in FileSystemView and can be used instead of using reflection
  • remove calls to ShellFolder.getShellFolder(file) entirely since there is no public equivalent still

this hopefully fixes the mysterious NPEs on windows caused by broken java.io.File instances with null paths.

fixes #7067
fixes #8040

 - some internal methods are now public in FileSystemView and can be
   used instead of using reflection
 - remove calls to ShellFolder.getShellFolder(file) entirely

this hopefully fixes the mysterious NPEs on windows caused by
broken java.io.File instances with null paths.
@mbien mbien added Code cleanup Platform [ci] enable platform tests (platform/*) UI User Interface ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Jan 3, 2025
@mbien mbien added this to the NB25 milestone Jan 3, 2025
Comment on lines -1914 to +1874
File sf = useShellFolder? getShellFolderForFile(canonical) : canonical;
File f = sf;
File f = canonical;
Copy link
Member Author

@mbien mbien Jan 3, 2025

Choose a reason for hiding this comment

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

this didn't seem to make a difference, removing this call allows us to remove the ShellFolder.getShellFolder(file) call site entirely, which has no public API equivalent.

There is a chance that this is the place which injected the broken java.io.File instances. If the public FileSystemView methods would have caused this, other projects would likely have noticed it too by now.

also see #8040 (comment) and #8040 (comment)

Copy link
Contributor

@lkishalmi lkishalmi left a comment

Choose a reason for hiding this comment

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

Looks good to me. BTW, what this useShellFolder does on Windows? I see a lot of custom code around it here and in the DelegatingChooserUI as well.

Is that still relevant/useful feature to have?

@mbien
Copy link
Member Author

mbien commented Jan 3, 2025

what this useShellFolder does on Windows?

@lkishalmi I think its a special windows specific file-link, can be "Desktop", "recent files", a drive or network folder (potentially a custom file explorer shortcut).

The JDK makes it a special java.io.File, however, it was observed that something injected broken file instances with null paths. You couldn't call any method on them, including toString() without causing NPEs somewhere since that field is not nullable.

Copy link
Contributor

@eirikbakke eirikbakke left a comment

Choose a reason for hiding this comment

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

Look OK; I assume you were testing it on Windows.

I don't have a Windows machine around at the moment, but I tested it on MacOS and at least confirmed it didn't immediately cause any problems there.

@mbien
Copy link
Member Author

mbien commented Jan 5, 2025

I assume you were testing it on Windows.

on win 10. Also on linux, but none of the methods return anything interesting on linux still #8040 (comment).

but I tested it on MacOS and at least confirmed it didn't immediately cause any problems there.

awesome, going to merge it soon

@mbien mbien merged commit 08bc688 into apache:master Jan 5, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) Code cleanup Platform [ci] enable platform tests (platform/*) UI User Interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Netbeans not being able to open any project Cannot open project with an unexpected exception
3 participants