JDK-8153355 : sun.net.util.IPAddressUtil.isIPv4LiteralAddress returns "true" for numeric values e.g. "4324"
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8u74
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2016-03-28
  • Updated: 2016-04-27
  • Resolved: 2016-04-04
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux dsmdmini-mint 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
I tried to use sun.net.util.IPAddressUtil.isIPv4LiteralAddress  method for IPv4 validation, but it returned 'true' for some numeric values, e.g. 4324, 543, 5345435, 345435. 

Maybe it is related to https://bugs.openjdk.java.net/browse/JDK-8087190

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the following line of code: sun.net.util.IPAddressUtil.isIPv4LiteralAddress("4324");

2. Observe, that 'true' is returned.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
'false' should be returned for numeric values without dots
ACTUAL -
'true' is returned

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
    public static void main (String[] args) {
        System.out.printf(((Boolean)IPAddressUtil.isIPv4LiteralAddress("43421")).toString());
    }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I don't have a workaround, other than using some type of regexp and not relying on JDK code.


Comments
This is a duplicate of JDK-8087190 and is fixed in JDK 9 and latest unreleased 8u version.
04-04-2016