Free Support Forum -

com.aspose.words.FileCorruptedException when specifying a password Aspose.Words for Java 10.4.0


I am doing some basic testing with Aspose Words for Java to open a protected (read-only) document. I have created a fresh docx
file a set the protection to read-only with the password '123'. When opening the document with the password specfied via the
understanding junit test case, the following exception is thrown, when specifying no Loadoptions in the 'new Document' constructor,
the call succeeds.


Aspose.Words for Java 10.4.0 (Aspose.Words.jdk16.jar)
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
Eclipse 3.5.1
JUnit 4.4

If needed i can send you the complete maven project

Regards Rob Sessink

-------- code snippit --------

package com.tenbrinke.docworks;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;

import com.aspose.words.Document;
import com.aspose.words.LoadFormat;
import com.aspose.words.LoadOptions;
import com.aspose.words.ProtectionType;

public class DocumentSectionProtectionTest extends TestCase {

private Document doc;

private LoadOptions options;

public void setUp() throws Exception {
options = new LoadOptions("123");

public void testOpenProtectedDocument() throws Exception {
doc = new Document("src/test/resources/templates/test_protection.docx",
assertEquals(ProtectionType.READ_ONLY, doc.getProtectionType());

-------- code snippit --------

-------- stacktrace --------

com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
at com.aspose.words.FileFormatUtil.a(
at com.aspose.words.Document.b(
at com.aspose.words.Document.a(
at com.aspose.words.Document.(
at org.tenbrinke.docworks.builder.aspose.DocumentSectionProtectionTest.testOpenProtecedDocument(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(
at junit.framework.TestCase.runBare(
at junit.framework.TestResult$1.protect(
at junit.framework.TestResult.runProtected(
at junit.framework.TestSuite.runTest(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
Caused by: java.lang.NullPointerException
at com.aspose.words.ea.(
at com.aspose.words.Document.b(
... 22 more


Thanks for your request. Could you please attach the document you are getting problem with? I will investigate the problem on my side and provide you more information.

Best regards,


Please see the attached document.

Regards Rob


Thank you for additional information. Your document is not encrypted it is just protected. If the document is not encrypted, set LoadingOptions Password to null or empty string.

In your case should use the following code to unprotect your document:

Document doc = new Document("C:\\Temp\\test_protection.docx");

doc.unprotect();"C:\\Temp\\out.docx", SaveFormat.DOCX);

Best regards,

Thank you for your response, i mixed up the concepts of protection and encryption, everythings works correct now.

Regards Rob


Please let me know in case of any issue, I will be glad to help you.

Best regards,