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

Registering custom MIME resolver extending org.openide.filesystems.MIMEResolver throws fatal error: FileUtil.getMIMEType(String extension) is deprecated. #8096

Open
bnyney2k opened this issue Dec 28, 2024 · 0 comments
Labels
kind:bug Bug report or fix needs:triage Requires attention from one of the committers

Comments

@bnyney2k
Copy link

bnyney2k commented Dec 28, 2024

Apache NetBeans version

Apache NetBeans 24

What happened

I am building a netbeans module for my PHP project and require that it resolves *.php files as "text/x-php" instead of current "text/x-php5" MIME type.

I have created a class:

package Classes.MIMEResolvers;

import org.openide.filesystems.FileObject;
import org.openide.filesystems.MIMEResolver;

/**
 *
 * @author User
 */
@MIMEResolver.Registration(
    displayName = "PHP Files",
    position = 100,
    resource = "/main/resources/mime/MIME-PHP.resolver.xml"
)

public class PHPFileResolver extends MIMEResolver {
    
    public PHPFileResolver(){
        super("text/x-php5");
    }
    
    
    @Override
    public String findMIMEType(FileObject fo) {
        // Use FileObject's own attributes or metadata for MIME type resolution
        String ext = fo.getExt();
        System.out.println("RESOLVING MIME FOR: " + fo.getNameExt());
        
        if (ext != null && "php".equalsIgnoreCase(ext)) {
            return "text/x-php";
        }
        return null; // Delegate to other resolvers if not recognized
    }
    
}

However, when I run the nbm package to launch the custom netbeans module, I get the following log, and the PHP projects fail to open:

java.lang.AssertionError: FileUtil.getMIMEType(String extension) is deprecated. Please, use FileUtil.getMIMEType(FileObject).
	at org.openide.filesystems.FileUtil.getMIMEType(FileUtil.java:1374)
	at org.netbeans.modules.openide.filesystems.declmime.FileElement$Type.getMIMEType(FileElement.java:503)
	at org.netbeans.modules.openide.filesystems.declmime.FileElement$Type.accept(FileElement.java:531)
	at org.netbeans.modules.openide.filesystems.declmime.FileElement$Type.access$300(FileElement.java:133)
	at org.netbeans.modules.openide.filesystems.declmime.FileElement.resolve(FileElement.java:76)
	at org.netbeans.modules.openide.filesystems.declmime.MIMEResolverImpl$Impl.findMIMEType(MIMEResolverImpl.java:426)
	at org.openide.filesystems.MIMESupport$CachedFileObject.resolveMIME(MIMESupport.java:346)
	at org.openide.filesystems.MIMESupport$CachedFileObject.getMIMEType(MIMESupport.java:287)
	at org.openide.filesystems.MIMESupport.findMIMEType(MIMESupport.java:111)
	at org.openide.filesystems.FileUtil.getMIMEType(FileUtil.java:1388)
	at org.openide.filesystems.FileObject.getMIMEType(FileObject.java:642)
	at org.openide.filesystems.AbstractFileObject.getMIMEType(AbstractFileObject.java:169)
	at org.netbeans.modules.parsing.api.Source.create(Source.java:120)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.indexEmbedding(RepositoryUpdater.java:3134)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.doIndex(RepositoryUpdater.java:2861)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.lambda$index$0(RepositoryUpdater.java:2626)
	at org.netbeans.modules.parsing.impl.indexing.errors.TaskCache.refreshTransaction(TaskCache.java:540)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.index(RepositoryUpdater.java:2625)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$AbstractRootsWork.lambda$scanSource$3(RepositoryUpdater.java:5735)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.lambda$runInContext$4(RepositoryUpdater.java:2119)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:288)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.runInContext(RepositoryUpdater.java:2117)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.runInContext(RepositoryUpdater.java:2098)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.access$1400(RepositoryUpdater.java:135)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$AbstractRootsWork.scanSource(RepositoryUpdater.java:5770)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$AbstractRootsWork.scanSources(RepositoryUpdater.java:5443)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$RootsWork.getDone(RepositoryUpdater.java:5075)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$InitialRootsWork.getDone(RepositoryUpdater.java:5842)
[catch] at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.doTheWork(RepositoryUpdater.java:3452)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task._run(RepositoryUpdater.java:6197)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task.access$3400(RepositoryUpdater.java:5855)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$2.lambda$call$0(RepositoryUpdater.java:6116)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:288)
	at org.netbeans.modules.parsing.impl.RunWhenScanFinishedSupport.performScan(RunWhenScanFinishedSupport.java:83)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$2.call(RepositoryUpdater.java:6116)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$2.call(RepositoryUpdater.java:6112)
	at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:153)
	at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:335)
	at org.netbeans.modules.parsing.nb.DataObjectEnvFactory.runPriorityIO(DataObjectEnvFactory.java:118)
	at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:67)
	at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task.run(RepositoryUpdater.java:6112)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1403)
	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2018)

Language / Project Type / NetBeans Component

NetBeans Module Project

How to reproduce

  1. Create class as specified in problem description.
  2. Right-click and run project
  3. Create or open PHP project.

Project should fail to open and error should be thrown in Project output.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 11

JDK

JDK 23

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

No response

Are you willing to submit a pull request?

No

@bnyney2k bnyney2k added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Bug report or fix needs:triage Requires attention from one of the committers
Projects
None yet
Development

No branches or pull requests

1 participant