XeroAPI/Xero-Java

Not able to manage Invoice, Reports, RepeatingInvoices & many other objects

AscendingEagle opened this issue · 5 comments

  • Version 4.25.0

Many methods are currently broken. This issue was already raised multiple times, closed, but never actually fixed. This is NOT a duplicate. The bug exist right now in the code in multiple locations.

To Reproduce
Try to update any resource. This bug concerns many different Xero objects. Not sure how many. Way to reproduce:

  • Trying to void an Invoice throws Exception
  • Trying to get RepeatingInvoices throws Exception
  • Trying to get Reports throws Exception
  • ... a lot of other Xero objects

One of many occurrences of this bug (AccountingApi.java):

UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Invoices/{InvoiceID}");

Expected code:

UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath()).path("/Invoices/{InvoiceID}");

Why is this a bug
UriBuilder.fromUri accepts only correctly formed URI strings. The { and } symbols are not allowed and will always throw exceptions. Best solution would be not to use the UriBuilder at all, since this introduces an unnecessary outdated dependency, which causes conflicts not addressed here.

Additional context
The Xero Java API is currently broken without this fix and mostly non-functional, and has been so for at least one year. This is a HUGE problem.

Hi @AscendingEagle , thanks for your submission.

Could you please clarify the exceptions you are encountering? I've just tested these methods with version 4.25.0 without error.

Here is the stack trace:

java.lang.IllegalArgumentException: Illegal character in path at index 42: https://api.xero.com/api.xro/2.0/Invoices/{InvoiceID}
	at java.base/java.net.URI.create(URI.java:903)
	at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:95)
	at com.xero.api.client.AccountingApi.updateInvoiceForHttpResponse(AccountingApi.java:25788)
	at com.xero.api.client.AccountingApi.updateInvoice(AccountingApi.java:25715)
	at ...
Caused by: java.net.URISyntaxException: Illegal character in path at index 42: https://api.xero.com/api.xro/2.0/Invoices/{InvoiceID}
	at java.base/java.net.URI$Parser.fail(URI.java:2970)
	at java.base/java.net.URI$Parser.checkChars(URI.java:3141)
	at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3223)
	at java.base/java.net.URI$Parser.parse(URI.java:3171)
	at java.base/java.net.URI.<init>(URI.java:620)
	at java.base/java.net.URI.create(URI.java:901)
	... 11 more

URI's are not allowed to have the characters { or } in their representation. It has been pointed out in the past: #214 (comment)

Thanks for the additional details. I have looked back through the linked issues and think I understand what is going on. The version of UriBuilder our SDK uses supports URI parameters with the characters { } . Here is the doc.

Your application must have some sort of dependency conflict where an older version of javax.ws.rs.core is being used. We can look into making changes but this bug is unique to those using an older URIBuilder.

Thanks for looking into it. Indeed, it seems that libraries from different vendors have different implementations for the UriBuilder. I was able to resolve the issue after trying out a few of them until one worked.

Glad to hear you were able to resolve the issue!