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

regex pattern working for JDK 8 does not work in JDK 9

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      java version "9.0.1"
      Java(TM) SE Runtime Environment (build 9.0.1+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux SELAB-SERVER2 4.13.0-26-generic #29~16.04.2-Ubuntu SMP Tue Jan 9 22:00:44 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      It can work in JDK8, but fail in JDK9.

      REGRESSION. Last worked in version 8u151

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_151"
      Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.AssertionError: expected:<-1.0> but was:<0.0>
      at org.junit.Assert.fail(Assert.java:88)
      at org.junit.Assert.failNotEquals(Assert.java:834)
      at org.junit.Assert.assertEquals(Assert.java:118)
      at org.junit.Assert.assertEquals(Assert.java:144)
      at edu.utd.cs.testjdk.test.testFact(test.java:43)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package edu.utd.cs.testjdk;

      import static org.junit.Assert.assertEquals;

      import java.io.Serializable;

      import java.util.regex.Matcher;
      import java.util.regex.Pattern;
      import org.junit.Test;

      public class test {

      @Test
      public void testFact() {
      Subject loc = new Subject("name", "-1.0,2.5");
      assertEquals(new Double(-1.0), loc.lat);
      }

      }

      class Subject implements Cloneable, Serializable{
      private int n;
          public Double lat;

          public Double lng;
          public final String place;
          public final String name;
          public Double heading;
          public Integer edgeId;
          
          private static final String _doublePattern = "-{0,1}\\d+(\\.\\d+){0,1}";
          private static final Pattern _latLonPattern = Pattern.compile("[^[\\d&&[-|+|.]]]*(" + _doublePattern
                  + ")(\\s*,\\s*|\\s+)(" + _doublePattern + ")\\D*");
          private static final Pattern _headingPattern = Pattern.compile("\\D*heading=("
                  + _doublePattern + ")\\D*");

          private static final Pattern _edgeIdPattern = Pattern.compile("\\D*edgeId=(\\d+)\\D*");

      public Subject(String name, String place) {
              this.name = name;
              this.place = place;

              if (place == null) {
                  return;
              }
              
              Matcher matcher = _latLonPattern.matcher(place);
              if (matcher.find()) {
                  this.lat = Double.parseDouble(matcher.group(1));
                  this.lng = Double.parseDouble(matcher.group(4));
              }
              
              matcher = _headingPattern.matcher(place);
              if (matcher.find()) {
                  this.heading = Double.parseDouble(matcher.group(1));
              }
              
              matcher = _edgeIdPattern.matcher(place);
              if (matcher.find()) {
                  this.edgeId = Integer.parseInt(matcher.group(1));
              }


      }
      }
      ---------- END SOURCE ----------

      SUPPORT :
      YES

      Attachments

        Issue Links

          Activity

            People

              sherman Xueming Shen
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: