getFieldCode return null in case of a hyperlink

When having 2 hyperlink the one that is deleted, is returning null when calling getField().getFieldCode(), this behavior is in version 24.6 as for 24.3 everything is fine.

I also have not found anything in release notes about any changes on this.
document.docx (40.8 KB)

@romanmarcu Could you please provide the document for testing?

I have a test that create a document, delete the hyperlink and the value is empty.

@Test
	/***
	 * Could not extract Field Code from a deleted hyperlink
	 * @throws Exception
	 */
	public void testGetFieldCode_OnHyperlink() throws Exception {
		Document document = new Document();
		DocumentBuilder builder = new DocumentBuilder(document);
		builder.writeln("Before Link");
		FieldHyperlink field1 = (FieldHyperlink) builder.insertHyperlink("Test1", "http://myurl1", false);
		field1.remove();
		FieldHyperlink field2 = (FieldHyperlink) builder.insertHyperlink("Test2", "http://myurl2", false);

		assertThat(field1.getFieldCode()).isNullOrEmpty();
		assertThat(field2.getFieldCode()).isEqualTo(" HYPERLINK \"http://myurl2\" ");
	}

@romanmarcu Unfortunatly, I can’t reproduce the issue on my side with document you’ve provided. getFieldCode() return an empty string.

I have this test that is failing on new version 24.6 but is not failing on 24.3 with the same document
document.docx (40.8 KB)

public void test() throws Exception {
	final InputStream rtf = this.getClass().getResourceAsStream("/docs/document.docx");

	final Document doc = AsposeWords.open(rtf, FileFormat.DOCX);
	Section section = doc.getSections().get(0);
	NodeCollection childNodes = section.getBody().getChildNodes(NodeType.ANY, false);
	Paragraph paragraph = (Paragraph) childNodes.get(0);
	childNodes = paragraph.getChildNodes(NodeType.ANY, false);

	Iterator it = childNodes.iterator();
	while (it.hasNext()) {
		Node node = (Node) it.next();
		if (node.getNodeType() == NodeType.FIELD_START) {
			FieldStart fieldStart = (FieldStart) node;
			assertThat(fieldStart.getField().getFieldCode()).isNotEmpty();
		}

	}
}

@romanmarcu There are two fields in your document. One of them is deleted and the other one is inserted. For the deleted one you got an empty string, for the inserted one you got the value of the field code. I tested this code on version 24.3 and it also failed with this assert.

Using the version 24.3 I get all the field code value even for deleted one:
HYPERLINK “http://www.google.com
HYPERLINK “mailto:myemail@mail.com?subject=Subject”

but for 24.6 I got just:
HYPERLINK “mailto:myemail@mail.com?subject=Subject”
the first 1 is empty

@romanmarcu Unfortunately, this is expected behavior. Fields do not support revisions. There was a bug in previous versions that provide you access to the properties of a hyperlink field. We apologize for any inconvenience caused.

Thanks for the response, could you help us to point out what fix from release note have fixed this issue?

@romanmarcu Unfortunatly, I don’t know the number of issue where the fix was made. This was in 24.4 release.