Skip to content

Indexing fails with CoderMalfunctionError when XML file contains invalid characters #4354

@niabot

Description

@niabot

Apache NetBeans version

Apache NetBeans 14

What happened

I have an "Java Application" project which contains some invalid XML files for testing purposes. The doctype specifies "utf-8" encoding, but they contain invalid UTF-8 characters.

If I open the Java project an CoderMalfunctionError is thrown during indexing, which stops indexing immediately. This results in not working/updating code completion in other opened projects (especially PHP projects).

<?xml version="1.0" encoding="utf-8"?>
<a b="Kostenträger"></a>

The file is actually saved using cp1252, which results in an invalid UTF-8 encoding for ä (0xE4).

test.xml.zip

java.lang.IllegalArgumentException: newPosition > limit: (1 > 0)
    at java.base/java.nio.Buffer.createPositionException(Buffer.java:341)
    at java.base/java.nio.Buffer.position(Buffer.java:316)
    at java.base/java.nio.ByteBuffer.position(ByteBuffer.java:1516)
    at java.base/java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:622)
    at org.netbeans.api.queries.FileEncodingQuery$ProxyCharset$ProxyDecoder.decodeLoop(FileEncodingQuery.java:191)
    at java.base/java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:585)
Caused: java.nio.charset.CoderMalfunctionError
    at java.base/java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:587)
    at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:305)
    at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:188)
    at java.base/java.io.InputStreamReader.read(InputStreamReader.java:177)
    at org.netbeans.modules.parsing.api.Source.createSnapshot(Source.java:360)
    at org.netbeans.modules.parsing.impl.SourceCache.createSnapshot(SourceCache.java:157)
    at org.netbeans.modules.parsing.impl.SourceCache.getSnapshot(SourceCache.java:132)
    at org.netbeans.modules.parsing.api.ResultIterator.getSnapshot(ResultIterator.java:86)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work$1T.run(RepositoryUpdater.java:3153)
    at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:586)
    at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:132)
    at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:116)
    at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:181)
    at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:178)
    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.TaskProcessor.runUserTask(TaskProcessor.java:178)
    at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:83)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.indexEmbedding(RepositoryUpdater.java:3253)
    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:5719)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.lambda$runInContext$4(RepositoryUpdater.java:2119)
    at org.openide.util.lookup.Lookups.executeWith(Lookups.java:279)
    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:5754)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$AbstractRootsWork.scanSources(RepositoryUpdater.java:5427)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$RootsWork.getDone(RepositoryUpdater.java:5059)
[catch] at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.doTheWork(RepositoryUpdater.java:3436)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task._run(RepositoryUpdater.java:6181)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task.access$3400(RepositoryUpdater.java:5839)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$2.lambda$call$0(RepositoryUpdater.java:6100)
    at org.openide.util.lookup.Lookups.executeWith(Lookups.java:279)
    at org.netbeans.modules.parsing.impl.RunWhenScanFinishedSupport.performScan(RunWhenScanFinishedSupport.java:83)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$2.call(RepositoryUpdater.java:6100)
    at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$2.call(RepositoryUpdater.java:6096)
    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:6096)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
    at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
    at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
    at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)

How to reproduce

Create a "Java Application" project. Copy the "test.xml" into some package of the project. Close and reopen the project and the Exception notification should be shown. Additionally it should not be possible to edit this file within Netbeans.

To circumvent the issue one can remove the invalid characters or remove the encoding="utf-8" from the doctype. Netbeans should not trust the encoding in the doctype.

Did this work correctly in an earlier version?

No

Operating System

Windows 10 64bit (should be OS independent)

JDK

OpenJDK 64-Bit Server VM 17+35-2724

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

No

Code of Conduct

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions