Jonatan Stenbacka
Jonatan Stenbacka

Reputation: 1864

FileChooser.ExtensionFilter does not filter .url files

I'm using the FileChooser to select a file, and I've added a ExtensionFilter to the FileChooser so that the user is restricted to choosing only the specified file type. In this case I want the restrict the user to selecting .xml files only.

The problem is that my ExtensionFilter allows the user to select not only .xml files, but also .url (internet shortcut) files. The ExtensionFilter does work almost perfect, since no other file types than the two is shown (to my knowledge; I've only tried with the most common file types).

This is my ExtensionFilter:

FileChooser.ExtensionFilter extensionFilter = new FileChooser.ExtensionFilter(
            "XML Files (*.xml)", "*.xml");

I tried changing it to allowing only .txt files instead, just to check if it maybe grouped .xml and .url together somehow, but with the same result. The FileChooser then shows both .txt and .url. So it seems that .url files somehow slips through the filtering process.

Is this perhaps a design bug?

Edit: Environment: Windows 8.1 Enterprise + Java 1.8.0_45

Update: This seems to be an issue that is bound to my environment. All tested environments except mine has failed to reproduce the issue. I managed to reproduce the issue on another computer with the same on environment. Can any one else try this in a Windows 8 environment and confirm the issue?

Tested environments that isn't able to reproduce the bug:

Here's a SSCCE that reproduces the described issue:

import javafx.application.Application;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

public class SSCCE extends Application {
    private Stage primaryStage;

    public void start(Stage primaryStage) {
        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("SSCCE");

    }

    public SSCCE() {
        FileChooser fileChooser = new FileChooser();

        FileChooser.ExtensionFilter extensionFilter = new FileChooser.ExtensionFilter(
                "XML Files (*.xml)", "*.xml");
        fileChooser.getExtensionFilters().add(extensionFilter);

        fileChooser.showOpenDialog(primaryStage);
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Upvotes: 2

Views: 746

Answers (1)

Kurt Naimaier
Kurt Naimaier

Reputation: 11

I was having the same problem (in windows 10) and want to share what I've found:

This bug was reported to OpenJDK and the answer was that this is a Windows issue and would not be fixed.

"Seems the showing of .url file types is a "known issue" in Windows, and there is not a clean or easy workaround for the issue." "Given that the core of this report is related to unfiltered .url files, and given that is a "feature" of Windows, I am closing this as will not fix." Source: https://bugs.openjdk.java.net/browse/JDK-8161668

Upvotes: 1

Related Questions