ipaddress.java can`t decode ipv6 address

public void decodeBER(BERInputStream inputStream) throws java.io.IOException {
BER.MutableByte type = new BER.MutableByte();
byte[] value = BER.decodeString(inputStream, type);
if (type.getValue() != BER.IPADDRESS) {
throw new IOException("Wrong type encountered when decoding Counter: "+
type.getValue());
}

//if remove this length check, ipv6 address will be support.
if (value.length != 4) {

  •  throw new IOException("IpAddress encoding error, wrong length: " +*
    
  •                        value.length);*
    
  • }*
    inetAddress = InetAddress.getByAddress(value);
    }

That is intended because the SMI type IpAddress is specified for IPv4 addresses only and is deprecated.

You should use OctetString instead as defined in the RFC 3419 (maybe updated meanwhile) within the TRANSPORT-ADDRESS-MIB.