I'm using java.net.URL.getPort() to extract the port number from a URL. Most of the time this works great. However, when the URL contains a right bracket character "]" it fails:
new URL("http://abc.com:123/abc.mp3").getPort();
returns: (int) 123
But if the URL contains "]" I get:
new URL("http://abc.com:123/abc].mp3").getPort();
returns: (int) -1
What am I doing wrong?
EDIT #1: As a test, I pasted this same code into a non-Android Java app and the port number was correctly returned, so this appears to be an anomaly with the Android SDK.