How to use getIPv4Octets

What is this function supposed to do?
I don’t have a clue what to do here.
I tried to assign every number of the host (IPv4Adress) into one byte and then put them into a array, but my tests are still failing with the error “Host must be an IPv4Adress” so… help? :joy:

The IllegalArgumentException "host must be an IPv4 address"
is thrown by getIPv4Octets if the host is not created as IPv4Address.
Only if the host is actually an IPv4Address, does it call getOctets.

You can inspect this code as it is part of the public unit tests in SimpleTests from line 26 to line 40.

The reason for this exception is that your parser does not generate an instance of IPv4Address as host where the tests expect such.

okay so I am supposed to generate an IPv4Adress every time the host looks like “[0-255].[0-255].[0-255].[0-255]” and otherwise just a “normal” Host?

If the host of an URL is a valid IPv4, the first branch of the grammar takes precedence.

1 Like