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

Free Support Forum - aspose.com

Aspose.Words for Java 10.1 migration - EmptyStackException

Hi,

I’m looking to migrate to Aspose.Words for Java 10.1 from an early release (I think 3.3).

When I run the following code I get an EmptyStackException. The method searches document for a cell containing merge field.

private Cell GetCellByMergeFieldName(String mergeFieldName) throws Exception
{
Cell cell = null;

NodeCollection nodeCollection = document.getChildNodes(NodeType.FIELD_START, true, false);
Iterator iterator = nodeCollection.iterator();

while (iterator.hasNext())
{
FieldStart node = (FieldStart)iterator.next();

if ((node.getFieldType() == FieldType.FIELD_MERGE_FIELD) && (node.getNextSibling().toTxt().indexOf(mergeFieldName) >= 0))
{
cell = (Cell)node.getAncestor(NodeType.CELL);
break;
}
}

return cell;
}


java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:79)
at com.aspose.words.atv.visitRun(TxtWriter.java:113)
at com.aspose.words.Run.accept(Run.java:88)
at com.aspose.words.atv.x(TxtWriter.java:67)
at com.aspose.words.Document.b(Document.java:1298)
at com.aspose.words.Node.toTxt(Node.java:571)


Thanks, Omnium

Hi

Thanks for your request. I think, it would be better to use code like the following to get cell where merge field is located:

private Cell GetCellByMergeFieldName(Document doc, String mergeFieldName) throws Exception

{

Cell cell = null;

DocumentBuilder builder = new DocumentBuilder(doc);

// Move DocumentBuilder cursor to the mergefield without removing the mergefield.

builder.moveToMergeField(mergeFieldName, true, false);

// Get cell

cell = (Cell)builder.getCurrentParagraph().getAncestor(NodeType.CELL);

return cell;

}

Hope this helps.

Best regards,

Thanks, this solution performs the same functionality and solves my issue.

Dear Sirs,


I am considering using Aspose Words for Java 10.1.0.

I am considering upgrading Aspose (4.0.3) to 10.1.0, but testing the trial i obtain a EmptyStackException everytime a use the Run.toTxt method.

Depending on the success of these tests we will purchase a new license - is this a know bug?


Kind Regards and Thanks in advance.

Hi

Thanks for your request. Yes, we are aware of this issue. We will let you know once this problem is resolved.

You can use Run.getText() instead of Run.toTxt() while you are waiting for a fix.

Best regards,

Hi Alexey,


I am in the same situation as alourinho with Aspose.Words 11.0.0: while testing Aspose.Words 11, the same EmptyStackException bug occurs when invoking Run.toTxt().

Unfortunately, we cannot consider working around this bug by means of the getTxt() you suggested.

Could you please provide us with a potentiel deadline for this bug’s effective correction? This is a crucial point to us.

Thanks in advance and kind regards,

Hi Dave,


Thanks for your request. As far i know, the exception is thrown when you try calling toTxt() method on Run that has no text. So as a workaround, you can simply check whether the Run has some text using getText() method and if so get text using toTxt(), otherwise simply ignore empty Run.
We will let you know once the problem is resolved. I will ask the responsible developer t take a look at the issue shortly.

Best regards,

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


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