8013878: ClassCastException in Regex

Fri, 03 May 2013 22:47:23 +0200

author
hannesw
date
Fri, 03 May 2013 22:47:23 +0200
changeset 249
c0f0033d7b08
parent 248
829b06307fb2
child 250
f98d22fa3cbc

8013878: ClassCastException in Regex
Reviewed-by: jlaskey

src/jdk/nashorn/internal/objects/NativeArray.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8013878.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8013878.js.EXPECTED file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java	Fri May 03 16:01:33 2013 +0200
     1.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java	Fri May 03 22:47:23 2013 +0200
     1.3 @@ -297,7 +297,7 @@
     1.4      @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
     1.5      public static Object length(final Object self) {
     1.6          if (isArray(self)) {
     1.7 -            return ((NativeArray) self).getArray().length() & JSType.MAX_UINT;
     1.8 +            return ((ScriptObject) self).getArray().length() & JSType.MAX_UINT;
     1.9          }
    1.10  
    1.11          return 0;
    1.12 @@ -311,7 +311,7 @@
    1.13      @Setter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
    1.14      public static void length(final Object self, final Object length) {
    1.15          if (isArray(self)) {
    1.16 -            ((NativeArray) self).setLength(validLength(length, true));
    1.17 +            ((ScriptObject) self).setLength(validLength(length, true));
    1.18          }
    1.19      }
    1.20  
    1.21 @@ -642,10 +642,9 @@
    1.22              final boolean      strict = sobj.isStrictContext();
    1.23  
    1.24              if (bulkable(sobj)) {
    1.25 -                final NativeArray nativeArray = (NativeArray)sobj;
    1.26 -                if (nativeArray.getArray().length() + args.length <= JSType.MAX_UINT) {
    1.27 -                    final ArrayData newData = nativeArray.getArray().push(nativeArray.isStrictContext(), args);
    1.28 -                    nativeArray.setArray(newData);
    1.29 +                if (sobj.getArray().length() + args.length <= JSType.MAX_UINT) {
    1.30 +                    final ArrayData newData = sobj.getArray().push(sobj.isStrictContext(), args);
    1.31 +                    sobj.setArray(newData);
    1.32                      return newData.length();
    1.33                  }
    1.34                  //fallthru
    1.35 @@ -780,8 +779,7 @@
    1.36          }
    1.37  
    1.38          if (bulkable(sobj)) {
    1.39 -            final NativeArray narray = (NativeArray) sobj;
    1.40 -            return new NativeArray(narray.getArray().slice(k, finale));
    1.41 +            return new NativeArray(sobj.getArray().slice(k, finale));
    1.42          }
    1.43  
    1.44          final NativeArray copy = new NativeArray(0);
    1.45 @@ -1001,11 +999,10 @@
    1.46          }
    1.47  
    1.48          if (bulkable(sobj)) {
    1.49 -            final NativeArray nativeArray = (NativeArray) sobj;
    1.50 -            nativeArray.getArray().shiftRight(items.length);
    1.51 +            sobj.getArray().shiftRight(items.length);
    1.52  
    1.53              for (int j = 0; j < items.length; j++) {
    1.54 -                nativeArray.setArray(nativeArray.getArray().set(j, items[j], sobj.isStrictContext()));
    1.55 +                sobj.setArray(sobj.getArray().set(j, items[j], sobj.isStrictContext()));
    1.56              }
    1.57          } else {
    1.58              for (long k = len; k > 0; k--) {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/script/basic/JDK-8013878.js	Fri May 03 22:47:23 2013 +0200
     2.3 @@ -0,0 +1,53 @@
     2.4 +/*
     2.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + * 
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + * 
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + * 
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + * 
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/**
    2.28 + * JDK-8013878: ClassCastException in Regex
    2.29 + *
    2.30 + * @test
    2.31 + * @run
    2.32 + */
    2.33 +
    2.34 +var re = /(a)(b)(c)/;
    2.35 +var str = 'abc';
    2.36 +
    2.37 +print(re.exec(str).length);
    2.38 +print(re.exec(str).concat(['d', 'e', 'f']));
    2.39 +print(re.exec(str).join('-'));
    2.40 +print(re.exec(str).push('d'));
    2.41 +print(re.exec(str).pop());
    2.42 +print(re.exec(str).reverse());
    2.43 +print(re.exec(str).shift());
    2.44 +print(re.exec(str).sort());
    2.45 +print(re.exec(str).slice(1));
    2.46 +print(re.exec(str).splice(1, 2, 'foo'));
    2.47 +print(re.exec(str).unshift('x'));
    2.48 +print(re.exec(str).indexOf('a'));
    2.49 +print(re.exec(str).lastIndexOf('a'));
    2.50 +print(re.exec(str).every(function(a) {return a.length;}));
    2.51 +print(re.exec(str).some(function(a) {return a.length;}));
    2.52 +print(re.exec(str).filter(function(a) {return a.length;}));
    2.53 +print(re.exec(str).forEach(function(a) {print(a)}));
    2.54 +print(re.exec(str).map(function(a) {return a.length;}));
    2.55 +print(re.exec(str).reduce(function(a, b) {return a + b}));
    2.56 +print(re.exec(str).reduceRight(function(a, b) {return a + b}));
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/basic/JDK-8013878.js.EXPECTED	Fri May 03 22:47:23 2013 +0200
     3.3 @@ -0,0 +1,24 @@
     3.4 +4
     3.5 +abc,a,b,c,d,e,f
     3.6 +abc-a-b-c
     3.7 +5
     3.8 +c
     3.9 +c,b,a,abc
    3.10 +abc
    3.11 +a,abc,b,c
    3.12 +a,b,c
    3.13 +a,b
    3.14 +5
    3.15 +1
    3.16 +1
    3.17 +true
    3.18 +true
    3.19 +abc,a,b,c
    3.20 +abc
    3.21 +a
    3.22 +b
    3.23 +c
    3.24 +undefined
    3.25 +3,1,1,1
    3.26 +abcabc
    3.27 +cbaabc

mercurial