We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Document.getPageCount throws java.lang.IllegalStateException with JDK 1.8 (32 bit)

Hello,
I tried the DocumentPrieviewAndPrint example in Javafrom github. I changed the input document to one of our documents and received the following exception:

Exception in thread “main” java.lang.IllegalStateException: Cannot happen
at com.aspose.words.PrinterMetrics.zzY(Unknown Source)
at com.aspose.words.PrinterMetrics.zzZ(Unknown Source)
at com.aspose.words.PrinterMetrics.zzZ(Unknown Source)
at com.aspose.words.PrinterMetrics.zzZ(Unknown Source)
at com.aspose.words.PrinterMetrics$PrinterFontMetrics.getTextWidthPoints(Unknown Source)
at com.aspose.words.internal.zzTI.zzg(Unknown Source)
at com.aspose.words.internal.zzTI.zze(Unknown Source)
at com.aspose.words.zz6C.zzQ(Unknown Source)
at com.aspose.words.zzYUB.zzYBU(Unknown Source)
at com.aspose.words.zzYVD.zz9M(Unknown Source)
at com.aspose.words.zzYVD.zzYj(Unknown Source)
at com.aspose.words.zzYUB.zzYj(Unknown Source)
at com.aspose.words.zzZJK.zzAr(Unknown Source)
at com.aspose.words.zzZJK.zzW(Unknown Source)
at com.aspose.words.zzZJK.zzUL(Unknown Source)
at com.aspose.words.zzZJD.zzZ(Unknown Source)
at com.aspose.words.zzZJD.zzM(Unknown Source)
at com.aspose.words.zzZJM.zzC(Unknown Source)
at com.aspose.words.zzZJM.zzU(Unknown Source)
at com.aspose.words.zzZJM.zzV(Unknown Source)
at com.aspose.words.zzW7.zzZ(Unknown Source)
at com.aspose.words.zzW7.zzZ(Unknown Source)
at com.aspose.words.zzYVU.zzYCB(Unknown Source)
at com.aspose.words.zzYVU.zzY(Unknown Source)
at com.aspose.words.zzYVU.zzZ(Unknown Source)
at com.aspose.words.zzZ4G.zzU(Unknown Source)
at com.aspose.words.zzZ4G.zzG(Unknown Source)
at com.aspose.words.zzYTY.zz9(Unknown Source)
at com.aspose.words.zzZXC.zzY(Unknown Source)
at com.aspose.words.zzZXC.zzX(Unknown Source)
at com.aspose.words.zzZXC.zzT(Unknown Source)
at com.aspose.words.zzZ55.zzN(Unknown Source)
at com.aspose.words.zzZ4G.zzG(Unknown Source)
at com.aspose.words.zzYTY.zz9(Unknown Source)
at com.aspose.words.zz8N.zzG(Unknown Source)
at com.aspose.words.zz8O.zzZFL(Unknown Source)
at com.aspose.words.zzZ5C.zzYRV(Unknown Source)
at com.aspose.words.Document.updatePageLayout(Unknown Source)
at com.aspose.words.Document.zzWH(Unknown Source)
at com.aspose.words.Document.getPageCount(Unknown Source)
at com.aspose.words.examples.rendering_printing.DocumentPreviewAndPrint.main(DocumentPreviewAndPrint.java:27)

Do you have any idea how to solve this issue?

I would append the document but do not know whether it is possible in here.

@Heiko_Voss

Could you please attach your input Word document here for testing? We will investigate the issue on our side and provide you more information.

Here is the document:
testHV.zip (73.5 KB)

@Heiko_Voss

We have tested the scenario using the latest version of Aspose.Words for Java 20.3 and have not found the shared issue. So, please use Aspose.Words for Java 20.3.

I tried with 20.3 and issue occured again:

"I am currently using Aspose.Words for Java, version number 20.3.

java.lang.IllegalStateException: Cannot happen
at com.aspose.words.PrinterMetrics.zzY(Unknown Source)
at com.aspose.words.PrinterMetrics.zzZ(Unknown Source)
at com.aspose.words.PrinterMetrics.zzZ(Unknown Source)
at com.aspose.words.PrinterMetrics.zzZ(Unknown Source)
at com.aspose.words.PrinterMetrics$PrinterFontMetrics.getTextWidthPoints(Unknown Source)
at com.aspose.words.internal.zzTI.zzg(Unknown Source)
at com.aspose.words.internal.zzTI.zze(Unknown Source)
at com.aspose.words.zz62.zzQ(Unknown Source)
at com.aspose.words.zzYU6.zzYBr(Unknown Source)
at com.aspose.words.zzYV8.zz9H(Unknown Source)
at com.aspose.words.zzYV8.zzYj(Unknown Source)
at com.aspose.words.zzYU6.zzYj(Unknown Source)
at com.aspose.words.zzZJI.zzAl(Unknown Source)
at com.aspose.words.zzZJI.zzW(Unknown Source)
at com.aspose.words.zzZJI.zzUK(Unknown Source)
at com.aspose.words.zzZJB.zzZ(Unknown Source)
at com.aspose.words.zzZJB.zzM(Unknown Source)
at com.aspose.words.zzZJK.zzC(Unknown Source)
at com.aspose.words.zzZJK.zzU(Unknown Source)
at com.aspose.words.zzZJK.zzV(Unknown Source)
at com.aspose.words.zzW5.zzZ(Unknown Source)
at com.aspose.words.zzW5.zzZ(Unknown Source)
at com.aspose.words.zzYVS.zzYCc(Unknown Source)
at com.aspose.words.zzYVS.zzY(Unknown Source)
at com.aspose.words.zzYVS.zzZ(Unknown Source)
at com.aspose.words.zzZ4F.zzU(Unknown Source)
at com.aspose.words.zzZ4F.zzG(Unknown Source)
at com.aspose.words.zzYTT.zz9(Unknown Source)
at com.aspose.words.zzZXA.zzY(Unknown Source)
at com.aspose.words.zzZXA.zzX(Unknown Source)
at com.aspose.words.zzZXA.zzT(Unknown Source)
at com.aspose.words.zzZ53.zzN(Unknown Source)
at com.aspose.words.zzZ4F.zzG(Unknown Source)
at com.aspose.words.zzYTT.zz9(Unknown Source)
at com.aspose.words.zz8L.zzG(Unknown Source)
at com.aspose.words.zz8M.zzZFF(Unknown Source)
at com.aspose.words.zzZ5A.zzYRA(Unknown Source)
at com.aspose.words.Document.updatePageLayout(Unknown Source)
at com.aspose.words.Document.zzWG(Unknown Source)
at com.aspose.words.Document.getPageCount(Unknown Source)
at com.aspose.words.examples.rendering_printing.DocumentPreviewAndPrint.main(DocumentPreviewAndPrint.java:33)"

I have downloaded the examples from github. I’m working with eclipse under Windows 10 with system language German.

Here is the source code:

package com.aspose.words.examples.rendering_printing;

import com.aspose.words.AsposeWordsPrintDocument;
import com.aspose.words.BuildVersionInfo;
import com.aspose.words.Document;
import com.aspose.words.examples.Utils;

import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.PageRanges;
import java.awt.print.PrinterJob;
import java.text.MessageFormat;

public class DocumentPreviewAndPrint {

private static final String dataDir = Utils.getSharedDataDir(DocumentPreviewAndPrint.class) + "RenderingAndPrinting/";

public static void main(String[] args) throws Exception {

	System.out.println(MessageFormat.format("I am currently using {0}, version number {1}.", BuildVersionInfo.getProduct(), BuildVersionInfo.getVersion()));
	
    // Open the document.
    //Document doc = new Document(dataDir + "TestFile.doc");
    Document doc = new Document(dataDir + "testHV.doc");

    //ExStart:PrintDialog
    PrinterJob pj = PrinterJob.getPrinterJob();

    // Initialize the Print Dialog with the number of pages in the document.
    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    try
    {
    	attributes.add(new PageRanges(1, doc.getPageCount()));
    }
    catch ( Exception e )
    {
    	e.printStackTrace();
    }

}
}

@Heiko_Voss

We used the same code example with your document and unable to reproduce this issue at our end. We tested this issue at Windows 10 with Java 8.

From the stacktrace, it looks like the issue appears when calling Document.updatePageLayout and Document.getPageCount methods. Could you please load your document into Aspose.Words’ DOM and call these methods? Please let us know if you still face the same issue. Please also share your Java version and operating system detail. We will investigate this issue further and provide you more information on it.

Hello,
The source code crashes in Document.getPageCount(). It crashes if you run the program with a 32bit-jre on 64bit Windows.

For development reasons I have different JREs on my computer installed. And today I checked different versions of JRE 1.8. The issue occurs on my 64bit Windows with 1.8.0_241 32bit and with 1.8.0_241 64bit the issue occurs not. I tried also some older JREs and had the same behaviour.

Now I will use the correct JRE. The issue is solved for me. Thanks for the fast and good support.

Greetings
Heiko

@Heiko_Voss

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSJAVA-2333. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hello,
Unfortunately I cannot change my program to a 64bit JRE (I tried it the last days). I have to work with Apose.Word and a 32bit JRE.
So it is quite important for me that the bug is found.

Thanks for the effort.

@Heiko_Voss

We will investigate this issue and inform you via this forum thread once there is an update available on it.

The issues you have found earlier (filed as WORDSJAVA-2333) have been fixed in this Aspose.Words for .NET 20.5 update and this Aspose.Words for Java 20.5 update.

Thanks for fixing. I will test it asap. Really great. Now we can use all functionality of the library we need.