8059443: NPE when unboxing return values

Mon, 03 Nov 2014 09:49:52 +0100

author
attila
date
Mon, 03 Nov 2014 09:49:52 +0100
changeset 1090
99571b7922c0
parent 1089
981feb6ad9cc
child 1091
628304057fce

8059443: NPE when unboxing return values
Reviewed-by: lagergren, sundar

src/jdk/internal/dynalink/DynamicLinkerFactory.java file | annotate | diff | comparison | revisions
src/jdk/internal/dynalink/linker/MethodTypeConversionStrategy.java file | annotate | diff | comparison | revisions
src/jdk/internal/dynalink/support/TypeConverterFactory.java file | annotate | diff | comparison | revisions
src/jdk/internal/dynalink/support/TypeUtilities.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/Bootstrap.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8059443.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8059443.js.EXPECTED file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/test/models/NullProvider.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/internal/dynalink/DynamicLinkerFactory.java	Thu Nov 06 17:06:56 2014 +0100
     1.2 +++ b/src/jdk/internal/dynalink/DynamicLinkerFactory.java	Mon Nov 03 09:49:52 2014 +0100
     1.3 @@ -97,6 +97,7 @@
     1.4  import jdk.internal.dynalink.linker.GuardingDynamicLinker;
     1.5  import jdk.internal.dynalink.linker.GuardingTypeConverterFactory;
     1.6  import jdk.internal.dynalink.linker.LinkRequest;
     1.7 +import jdk.internal.dynalink.linker.MethodTypeConversionStrategy;
     1.8  import jdk.internal.dynalink.support.AutoDiscovery;
     1.9  import jdk.internal.dynalink.support.BottomGuardingDynamicLinker;
    1.10  import jdk.internal.dynalink.support.ClassLoaderGetterContextProvider;
    1.11 @@ -105,6 +106,7 @@
    1.12  import jdk.internal.dynalink.support.DefaultPrelinkFilter;
    1.13  import jdk.internal.dynalink.support.LinkerServicesImpl;
    1.14  import jdk.internal.dynalink.support.TypeConverterFactory;
    1.15 +import jdk.internal.dynalink.support.TypeUtilities;
    1.16  
    1.17  /**
    1.18   * A factory class for creating {@link DynamicLinker}s. The most usual dynamic linker is a linker that is a composition
    1.19 @@ -115,7 +117,6 @@
    1.20   * @author Attila Szegedi
    1.21   */
    1.22  public class DynamicLinkerFactory {
    1.23 -
    1.24      /**
    1.25       * Default value for {@link #setUnstableRelinkThreshold(int) unstable relink threshold}.
    1.26       */
    1.27 @@ -130,6 +131,7 @@
    1.28      private boolean syncOnRelink = false;
    1.29      private int unstableRelinkThreshold = DEFAULT_UNSTABLE_RELINK_THRESHOLD;
    1.30      private GuardedInvocationFilter prelinkFilter;
    1.31 +    private MethodTypeConversionStrategy autoConversionStrategy;
    1.32  
    1.33      /**
    1.34       * Sets the class loader for automatic discovery of available linkers. If not set explicitly, then the thread
    1.35 @@ -259,6 +261,29 @@
    1.36      }
    1.37  
    1.38      /**
    1.39 +     * Sets an object representing the conversion strategy for automatic type conversions. After
    1.40 +     * {@link TypeConverterFactory#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)} has
    1.41 +     * applied all custom conversions to a method handle, it still needs to effect
    1.42 +     * {@link TypeUtilities#isMethodInvocationConvertible(Class, Class) method invocation conversions} that
    1.43 +     * can usually be automatically applied as per
    1.44 +     * {@link java.lang.invoke.MethodHandle#asType(java.lang.invoke.MethodType)}.
    1.45 +     * However, sometimes language runtimes will want to customize even those conversions for their own call
    1.46 +     * sites. A typical example is allowing unboxing of null return values, which is by default prohibited by
    1.47 +     * ordinary {@code MethodHandles.asType}. In this case, a language runtime can install its own custom
    1.48 +     * automatic conversion strategy, that can deal with null values. Note that when the strategy's
    1.49 +     * {@link MethodTypeConversionStrategy#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)}
    1.50 +     * is invoked, the custom language conversions will already have been applied to the method handle, so by
    1.51 +     * design the difference between the handle's current method type and the desired final type will always
    1.52 +     * only be ones that can be subjected to method invocation conversions. The strategy also doesn't need to
    1.53 +     * invoke a final {@code MethodHandle.asType()} as the converter factory will do that as the final step.
    1.54 +     * @param autoConversionStrategy the strategy for applying method invocation conversions for the linker
    1.55 +     * created by this factory.
    1.56 +     */
    1.57 +    public void setAutoConversionStrategy(final MethodTypeConversionStrategy autoConversionStrategy) {
    1.58 +        this.autoConversionStrategy = autoConversionStrategy;
    1.59 +    }
    1.60 +
    1.61 +    /**
    1.62       * Creates a new dynamic linker consisting of all the prioritized, autodiscovered, and fallback linkers as well as
    1.63       * the pre-link filter.
    1.64       *
    1.65 @@ -324,8 +349,9 @@
    1.66              prelinkFilter = new DefaultPrelinkFilter();
    1.67          }
    1.68  
    1.69 -        return new DynamicLinker(new LinkerServicesImpl(new TypeConverterFactory(typeConverters), composite),
    1.70 -                prelinkFilter, runtimeContextArgCount, syncOnRelink, unstableRelinkThreshold);
    1.71 +        return new DynamicLinker(new LinkerServicesImpl(new TypeConverterFactory(typeConverters,
    1.72 +                autoConversionStrategy), composite), prelinkFilter, runtimeContextArgCount, syncOnRelink,
    1.73 +                unstableRelinkThreshold);
    1.74      }
    1.75  
    1.76      private static ClassLoader getThreadContextClassLoader() {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/jdk/internal/dynalink/linker/MethodTypeConversionStrategy.java	Mon Nov 03 09:49:52 2014 +0100
     2.3 @@ -0,0 +1,100 @@
     2.4 +/*
     2.5 + * Copyright (c) 2014, 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.  Oracle designates this
    2.11 + * particular file as subject to the "Classpath" exception as provided
    2.12 + * by Oracle in the LICENSE file that accompanied this code.
    2.13 + *
    2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.17 + * version 2 for more details (a copy is included in the LICENSE file that
    2.18 + * accompanied this code).
    2.19 + *
    2.20 + * You should have received a copy of the GNU General Public License version
    2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.23 + *
    2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.25 + * or visit www.oracle.com if you need additional information or have any
    2.26 + * questions.
    2.27 + */
    2.28 +
    2.29 +/*
    2.30 + * This file is available under and governed by the GNU General Public
    2.31 + * License version 2 only, as published by the Free Software Foundation.
    2.32 + * However, the following notice accompanied the original version of this
    2.33 + * file, and Oracle licenses the original version of this file under the BSD
    2.34 + * license:
    2.35 + */
    2.36 +/*
    2.37 +   Copyright 2014 Attila Szegedi
    2.38 +
    2.39 +   Licensed under both the Apache License, Version 2.0 (the "Apache License")
    2.40 +   and the BSD License (the "BSD License"), with licensee being free to
    2.41 +   choose either of the two at their discretion.
    2.42 +
    2.43 +   You may not use this file except in compliance with either the Apache
    2.44 +   License or the BSD License.
    2.45 +
    2.46 +   If you choose to use this file in compliance with the Apache License, the
    2.47 +   following notice applies to you:
    2.48 +
    2.49 +       You may obtain a copy of the Apache License at
    2.50 +
    2.51 +           http://www.apache.org/licenses/LICENSE-2.0
    2.52 +
    2.53 +       Unless required by applicable law or agreed to in writing, software
    2.54 +       distributed under the License is distributed on an "AS IS" BASIS,
    2.55 +       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    2.56 +       implied. See the License for the specific language governing
    2.57 +       permissions and limitations under the License.
    2.58 +
    2.59 +   If you choose to use this file in compliance with the BSD License, the
    2.60 +   following notice applies to you:
    2.61 +
    2.62 +       Redistribution and use in source and binary forms, with or without
    2.63 +       modification, are permitted provided that the following conditions are
    2.64 +       met:
    2.65 +       * Redistributions of source code must retain the above copyright
    2.66 +         notice, this list of conditions and the following disclaimer.
    2.67 +       * Redistributions in binary form must reproduce the above copyright
    2.68 +         notice, this list of conditions and the following disclaimer in the
    2.69 +         documentation and/or other materials provided with the distribution.
    2.70 +       * Neither the name of the copyright holder nor the names of
    2.71 +         contributors may be used to endorse or promote products derived from
    2.72 +         this software without specific prior written permission.
    2.73 +
    2.74 +       THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    2.75 +       IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    2.76 +       TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    2.77 +       PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
    2.78 +       BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    2.79 +       CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    2.80 +       SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
    2.81 +       BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    2.82 +       WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    2.83 +       OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    2.84 +       ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2.85 +*/
    2.86 +
    2.87 +package jdk.internal.dynalink.linker;
    2.88 +
    2.89 +import java.lang.invoke.MethodHandle;
    2.90 +import java.lang.invoke.MethodType;
    2.91 +
    2.92 +/**
    2.93 + * Interface for objects representing a strategy for converting a method handle to a new type.
    2.94 + */
    2.95 +public interface MethodTypeConversionStrategy {
    2.96 +    /**
    2.97 +     * Converts a method handle to a new type.
    2.98 +     * @param target target method handle
    2.99 +     * @param newType new type
   2.100 +     * @return target converted to the new type.
   2.101 +     */
   2.102 +    public MethodHandle asType(final MethodHandle target, final MethodType newType);
   2.103 +}
     3.1 --- a/src/jdk/internal/dynalink/support/TypeConverterFactory.java	Thu Nov 06 17:06:56 2014 +0100
     3.2 +++ b/src/jdk/internal/dynalink/support/TypeConverterFactory.java	Mon Nov 03 09:49:52 2014 +0100
     3.3 @@ -97,6 +97,7 @@
     3.4  import jdk.internal.dynalink.linker.GuardedTypeConversion;
     3.5  import jdk.internal.dynalink.linker.GuardingTypeConverterFactory;
     3.6  import jdk.internal.dynalink.linker.LinkerServices;
     3.7 +import jdk.internal.dynalink.linker.MethodTypeConversionStrategy;
     3.8  
     3.9  /**
    3.10   * A factory for type converters. This class is the main implementation behind the
    3.11 @@ -109,6 +110,7 @@
    3.12  
    3.13      private final GuardingTypeConverterFactory[] factories;
    3.14      private final ConversionComparator[] comparators;
    3.15 +    private final MethodTypeConversionStrategy autoConversionStrategy;
    3.16  
    3.17      private final ClassValue<ClassMap<MethodHandle>> converterMap = new ClassValue<ClassMap<MethodHandle>>() {
    3.18          @Override
    3.19 @@ -177,8 +179,24 @@
    3.20       * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances.
    3.21       *
    3.22       * @param factories the {@link GuardingTypeConverterFactory} instances to compose.
    3.23 +     * @param autoConversionStrategy conversion strategy for automatic type conversions. After
    3.24 +     * {@link #asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)} has applied all custom
    3.25 +     * conversions to a method handle, it still needs to effect
    3.26 +     * {@link TypeUtilities#isMethodInvocationConvertible(Class, Class) method invocation conversions} that
    3.27 +     * can usually be automatically applied as per
    3.28 +     * {@link java.lang.invoke.MethodHandle#asType(java.lang.invoke.MethodType)}.
    3.29 +     * However, sometimes language runtimes will want to customize even those conversions for their own call
    3.30 +     * sites. A typical example is allowing unboxing of null return values, which is by default prohibited by
    3.31 +     * ordinary {@code MethodHandles.asType}. In this case, a language runtime can install its own custom
    3.32 +     * automatic conversion strategy, that can deal with null values. Note that when the strategy's
    3.33 +     * {@link MethodTypeConversionStrategy#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)}
    3.34 +     * is invoked, the custom language conversions will already have been applied to the method handle, so by
    3.35 +     * design the difference between the handle's current method type and the desired final type will always
    3.36 +     * only be ones that can be subjected to method invocation conversions. Can be null, in which case no
    3.37 +     * custom strategy is employed.
    3.38       */
    3.39 -    public TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories) {
    3.40 +    public TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories,
    3.41 +            final MethodTypeConversionStrategy autoConversionStrategy) {
    3.42          final List<GuardingTypeConverterFactory> l = new LinkedList<>();
    3.43          final List<ConversionComparator> c = new LinkedList<>();
    3.44          for(final GuardingTypeConverterFactory factory: factories) {
    3.45 @@ -189,20 +207,24 @@
    3.46          }
    3.47          this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
    3.48          this.comparators = c.toArray(new ConversionComparator[c.size()]);
    3.49 -
    3.50 +        this.autoConversionStrategy = autoConversionStrategy;
    3.51      }
    3.52  
    3.53      /**
    3.54       * Similar to {@link MethodHandle#asType(MethodType)} except it also hooks in method handles produced by
    3.55       * {@link GuardingTypeConverterFactory} implementations, providing for language-specific type coercing of
    3.56 -     * parameters. It will apply {@link MethodHandle#asType(MethodType)} for all primitive-to-primitive,
    3.57 -     * wrapper-to-primitive, primitive-to-wrapper conversions as well as for all upcasts. For all other conversions,
    3.58 -     * it'll insert {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)} with composite filters
    3.59 -     * provided by {@link GuardingTypeConverterFactory} implementations.
    3.60 +     * parameters. For all conversions that are not a JLS method invocation conversion it'll insert
    3.61 +     * {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)} with composite filters
    3.62 +     * provided by {@link GuardingTypeConverterFactory} implementations. For the remaining JLS method invocation
    3.63 +     * conversions, it will invoke {@link MethodTypeConversionStrategy#asType(MethodHandle, MethodType)} first
    3.64 +     * if an automatic conversion strategy was specified in the
    3.65 +     * {@link #TypeConverterFactory(Iterable, MethodTypeConversionStrategy) constructor}, and finally apply
    3.66 +     * {@link MethodHandle#asType(MethodType)} for any remaining conversions.
    3.67       *
    3.68       * @param handle target method handle
    3.69       * @param fromType the types of source arguments
    3.70 -     * @return a method handle that is a suitable combination of {@link MethodHandle#asType(MethodType)} and
    3.71 +     * @return a method handle that is a suitable combination of {@link MethodHandle#asType(MethodType)},
    3.72 +     * {@link MethodTypeConversionStrategy#asType(MethodHandle, MethodType)}, and
    3.73       * {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)} with
    3.74       * {@link GuardingTypeConverterFactory} produced type converters as filters.
    3.75       */
    3.76 @@ -246,8 +268,12 @@
    3.77              }
    3.78          }
    3.79  
    3.80 -        // Take care of automatic conversions
    3.81 -        return newHandle.asType(fromType);
    3.82 +        // Give change to automatic conversion strategy, if one is present.
    3.83 +        final MethodHandle autoConvertedHandle =
    3.84 +                autoConversionStrategy != null ? autoConversionStrategy.asType(newHandle, fromType) : newHandle;
    3.85 +
    3.86 +        // Do a final asType for any conversions that remain.
    3.87 +        return autoConvertedHandle.asType(fromType);
    3.88      }
    3.89  
    3.90      private static MethodHandle applyConverters(final MethodHandle handle, final int pos, final List<MethodHandle> converters) {
     4.1 --- a/src/jdk/internal/dynalink/support/TypeUtilities.java	Thu Nov 06 17:06:56 2014 +0100
     4.2 +++ b/src/jdk/internal/dynalink/support/TypeUtilities.java	Mon Nov 03 09:49:52 2014 +0100
     4.3 @@ -520,4 +520,13 @@
     4.4      public static Class<?> getWrapperType(final Class<?> primitiveType) {
     4.5          return WRAPPER_TYPES.get(primitiveType);
     4.6      }
     4.7 +
     4.8 +    /**
     4.9 +     * Returns true if the passed type is a wrapper for a primitive type.
    4.10 +     * @param type the examined type
    4.11 +     * @return true if the passed type is a wrapper for a primitive type.
    4.12 +     */
    4.13 +    public static boolean isWrapperType(final Class<?> type) {
    4.14 +        return PRIMITIVE_TYPES.containsKey(type);
    4.15 +    }
    4.16  }
     5.1 --- a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Thu Nov 06 17:06:56 2014 +0100
     5.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Mon Nov 03 09:49:52 2014 +0100
     5.3 @@ -42,6 +42,8 @@
     5.4  import jdk.internal.dynalink.linker.GuardedInvocation;
     5.5  import jdk.internal.dynalink.linker.LinkRequest;
     5.6  import jdk.internal.dynalink.linker.LinkerServices;
     5.7 +import jdk.internal.dynalink.linker.MethodTypeConversionStrategy;
     5.8 +import jdk.internal.dynalink.support.TypeUtilities;
     5.9  import jdk.nashorn.api.scripting.JSObject;
    5.10  import jdk.nashorn.internal.codegen.CompilerConstants.Call;
    5.11  import jdk.nashorn.internal.codegen.ObjectClassGenerator;
    5.12 @@ -106,6 +108,12 @@
    5.13                  return OptimisticReturnFilters.filterOptimisticReturnValue(inv, desc).asType(linkerServices, desc.getMethodType());
    5.14              }
    5.15          });
    5.16 +        factory.setAutoConversionStrategy(new MethodTypeConversionStrategy() {
    5.17 +            @Override
    5.18 +            public MethodHandle asType(final MethodHandle target, final MethodType newType) {
    5.19 +                return unboxReturnType(target, newType);
    5.20 +            }
    5.21 +        });
    5.22          final int relinkThreshold = Options.getIntProperty("nashorn.unstable.relink.threshold", NASHORN_DEFAULT_UNSTABLE_RELINK_THRESHOLD);
    5.23          if (relinkThreshold > -1) {
    5.24              factory.setUnstableRelinkThreshold(relinkThreshold);
    5.25 @@ -420,4 +428,29 @@
    5.26      static GuardedInvocation asTypeSafeReturn(final GuardedInvocation inv, final LinkerServices linkerServices, final CallSiteDescriptor desc) {
    5.27          return inv == null ? null : inv.asTypeSafeReturn(linkerServices, desc.getMethodType());
    5.28      }
    5.29 +
    5.30 +    /**
    5.31 +     * Adapts the return type of the method handle with {@code explicitCastArguments} when it is an unboxing
    5.32 +     * conversion. This will ensure that nulls are unwrapped to false or 0.
    5.33 +     * @param target the target method handle
    5.34 +     * @param newType the desired new type. Note that this method does not adapt the method handle completely to the
    5.35 +     * new type, it only adapts the return type; this is allowed as per
    5.36 +     * {@link DynamicLinkerFactory#setAutoConversionStrategy(MethodTypeConversionStrategy)}, which is what this method
    5.37 +     * is used for.
    5.38 +     * @return the method handle with adapted return type, if it required an unboxing conversion.
    5.39 +     */
    5.40 +    private static MethodHandle unboxReturnType(final MethodHandle target, final MethodType newType) {
    5.41 +        final MethodType targetType = target.type();
    5.42 +        final Class<?> oldReturnType = targetType.returnType();
    5.43 +        if (TypeUtilities.isWrapperType(oldReturnType)) {
    5.44 +            final Class<?> newReturnType = newType.returnType();
    5.45 +            if (newReturnType.isPrimitive()) {
    5.46 +                // The contract of setAutoConversionStrategy is such that the difference between newType and targetType
    5.47 +                // can only be JLS method invocation conversions.
    5.48 +                assert TypeUtilities.isMethodInvocationConvertible(oldReturnType, newReturnType);
    5.49 +                return MethodHandles.explicitCastArguments(target, targetType.changeReturnType(newReturnType));
    5.50 +            }
    5.51 +        }
    5.52 +        return target;
    5.53 +    }
    5.54  }
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/script/basic/JDK-8059443.js	Mon Nov 03 09:49:52 2014 +0100
     6.3 @@ -0,0 +1,39 @@
     6.4 +/*
     6.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + * 
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + * 
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + * 
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + * 
    6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 + * or visit www.oracle.com if you need additional information or have any
    6.24 + * questions.
    6.25 + */
    6.26 +
    6.27 +/**
    6.28 + * JDK-8059443: NPE when unboxing return values
    6.29 + * 
    6.30 + * NOTE: this test can only pass when running with a JDK where 
    6.31 + * JDK-8060483 is also fixed (9b37 or later).
    6.32 + *
    6.33 + * @test
    6.34 + * @run
    6.35 + */
    6.36 +
    6.37 +var NullProvider = Java.type("jdk.nashorn.test.models.NullProvider");
    6.38 +
    6.39 +if (!NullProvider.getBoolean()) { print("yay"); }
    6.40 +print(NullProvider.getLong() * (1 << 33));
    6.41 +print(NullProvider.getDouble() / 2.5);
    6.42 +print(NullProvider.getInteger() << 1);
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/script/basic/JDK-8059443.js.EXPECTED	Mon Nov 03 09:49:52 2014 +0100
     7.3 @@ -0,0 +1,4 @@
     7.4 +yay
     7.5 +0
     7.6 +0
     7.7 +0
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/src/jdk/nashorn/test/models/NullProvider.java	Mon Nov 03 09:49:52 2014 +0100
     8.3 @@ -0,0 +1,34 @@
     8.4 +/*
     8.5 + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + *
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.  Oracle designates this
    8.11 + * particular file as subject to the "Classpath" exception as provided
    8.12 + * by Oracle in the LICENSE file that accompanied this code.
    8.13 + *
    8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.17 + * version 2 for more details (a copy is included in the LICENSE file that
    8.18 + * accompanied this code).
    8.19 + *
    8.20 + * You should have received a copy of the GNU General Public License version
    8.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.23 + *
    8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.25 + * or visit www.oracle.com if you need additional information or have any
    8.26 + * questions.
    8.27 + */
    8.28 +
    8.29 +package jdk.nashorn.test.models;
    8.30 +
    8.31 +
    8.32 +public class NullProvider {
    8.33 +    public static Integer getInteger() { return null; }
    8.34 +    public static Long getLong() { return null; }
    8.35 +    public static Double getDouble() { return null; }
    8.36 +    public static Boolean getBoolean() { return null; }
    8.37 +}

mercurial