Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8054978

java.time.Duration.parse() fails for negative duration with 0 seconds and nanos

XMLWordPrintable

    • b94
    • x86_64
    • windows_7

        FULL PRODUCT VERSION :
        java version "1.8.0_11"
        Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
        Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Windows 7 64-bit

        A DESCRIPTION OF THE PROBLEM :
        First of all sorry if this is not in the correct category, I could not find the relevant category for java.time.*

        When parsing a negative Duration with 0 seconds and a few nanoseconds, the nanoseconds are wrongly considered positive:

        System.out.println(Duration.parse("PT-1.5S")); // PT-1.5S : ok
        System.out.println(Duration.parse("PT-0.5S")); // PT0.5S : error



        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        System.out.println(Duration.parse("PT-0.5S"));

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        PT-0.5S
        ACTUAL -
        PT0.5S

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package com.company;

        import java.time.*;

        public class Main {
            public static void main(String[] args) {

                System.out.println(Duration.parse("PT-0.5S"));
            }
        }

        ---------- END SOURCE ----------

              ntv Nadeesh Tv
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: