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

Free Support Forum - aspose.com

NullPointerException while retrieving stroke color on Shape object

Hi,
We are currently evaluating Aspose Words Java 16.12 version and hit into NullPointerException issue when retrieving Stroke color on Shape object in the below specified way.

Take the attached document “HeaderFooterWithShape.docx” and run the below test code.

Then what we observed is that, it generates NullPointerException where there is a call to “getStrokeColor()” before and after “getShapeRenderer()” call on the shape object…

… So there should be two calls to “getStrokeColor()” method on the Shape object… One is called before the call to “getShapeRenderer()” method, and the other is called after the call to “getShapeRenderer()” method… Then the NullPointerException occurs in the second call to the “getStrokeColor()” method which is placed after the call to “getShapeRenderer()” method.

Test Code:


public static void main(String[] args) throws Exception {
License license = new License();
license.setLicense(“Aspose.Words.lic”);
Document doc = new Document(“HeaderFooterWithShape.docx”);
// Get the shape nodes in the document.
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
// Get stroke color from the shape.
Shape shape = (Shape)shapes.get(0);
shape.getStrokeColor();
shape.getShapeRenderer();
shape.getStrokeColor(); // <— NullPointerException comes at this line
}

NOTE:

#1) In the attached test document, the shape object is present in the Header/Footer.
So alternatively you can get the child shape node from header/footer as well in the following way.

HeaderFooter headerFooter = doc.getSections().get(0).getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY);
NodeCollection shapes = headerFooter.getChildNodes(NodeType.SHAPE, true);
(OR)
HeaderFooter headerFooter = doc.getSections().get(0).getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_PRIMARY);
NodeCollection shapes = headerFooter.getChildNodes(NodeType.SHAPE, true);

#2) Any of the following call sequences is producing the NullPointerException.

shape.getStroke().getColor();
shape.getShapeRenderer();
shape.getStroke().getColor();
(OR)
shape.getStroke().getColor();
shape.getShapeRenderer();
shape.getStrokeColor();
(OR)
shape.getStrokeColor();
shape.getShapeRenderer();
shape.getStroke().getColor();

#3) However, following call sequences is NOT producing the NullPointerException. Because I guess these do NOT make two calls to get shape stroke color before and after the call to “getShapeRenderer()” method, or something like that…

shape.getStroke();
shape.getShapeRenderer();
shape.getStrokeColor();
(OR)
shape.getShapeRenderer();
shape.getStroke().getColor();
shape.getStrokeColor();
(OR)
shape.getStroke();
shape.getShapeRenderer();
shape.getStroke();
(OR)
shape.getShapeRenderer();
shape.getStrokeColor();
shape.getStroke().getColor();
shape.getStrokeColor();
shape.getStroke().getColor();


Can you please check this… and provide any fix or workaround for this?

Thanks,
-Satya

Hi Satya,

Thanks for your inquiry. 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 WORDSNET-14671. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@oraspose,

The issues you have found earlier (filed as WORDSNET-14671) have been fixed in this Aspose.Words for .NET 17.10 update and this Aspose.Words for Java 17.10 update.