Detect File Format & Throw UnsupportedFileFormatException when Opening an Invalid PDF File with Aspose.Words for .NET C# API

We’re having some unit tests which ran through without trouble on
the Aspose.Words 10 BETA version but have one that fails in 10.0.1:
When we do:

new AsposeWordFile(getClass().getResourceAsStream("/some.pdf"));

We’d expect an IOException because that file is no valid DOC (it’s a valid PDF), but instead we get:

java.lang.Exception: Unexpected exception, expected <> but was <java.util.ServiceConfigurationError>
Caused by: java.util.ServiceConfigurationError: java.nio.charset.spi.CharsetProvider: Provider not found
at java.util.ServiceLoader.access$400(
at java.util.ServiceLoader$
at java.util.ServiceLoader$
at java.nio.charset.Charset$1.getNext(
at java.nio.charset.Charset$1.hasNext( 351)
at java.nio.charset.Charset$ 394)
at java.nio.charset.Charset$ 392)
at Method)
at java.nio.charset.Charset.lookupViaProviders( 391)
at java.nio.charset.Charset.lookup2( 468)
at java.nio.charset.Charset.lookup( 456)
at java.nio.charset.Charset.forName( 521)
at 502)
at asposewobfuscated.rv.pi( 468)
at asposewobfuscated.rv.a( 452)
at asposewobfuscated.rv.m( 392)
at 318)
at 304)
at 44)
at com.aspose.words.Document.b( 1108)
at com.aspose.words.Document.a( 1084)
at com.aspose.words.Document.( 194)
at com.aspose.words.Document.( 165)
at com.aspose.words.Document.( 160)

Could you have a look at it?

Matt Keller

Thanks for your request. I managed to reproduce the problem on my side. You are right, there should be UnsupportedFileFormatException. I logged this problem into our defect database. We will let you know once it is resolved.
Best regards,

But please either throw some subclass of IOException (preferred) or clearly document that new exception in the javadoc and release notes.
The current javadoc states:

IOException - if the stream could not be read or does not contain a Word document


Hi Matt,
Thanks for your request. Andrey is right – UnsupportedFileFormatException should be thrown. Please see the following link for more details:
Since Aspose.Words does not support PDF as input document format – this type of exception should be thrown.
Best regards,

That’s okay with me, just as long as this exception is clearly documented in the javadoc and method signature.

The issues you have found earlier (filed as WORDSJAVA-7) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.