< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandles.java

Print this page
rev 13458 : 8147078: MethodHandles.catchException does not enforce Throwable subtype

*** 1,7 **** /* ! * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 3118,3127 **** --- 3118,3129 ---- MethodHandle catchException(MethodHandle target, Class<? extends Throwable> exType, MethodHandle handler) { MethodType ttype = target.type(); MethodType htype = handler.type(); + if (!Throwable.class.isAssignableFrom(exType)) + throw new ClassCastException(exType.getName()); if (htype.parameterCount() < 1 || !htype.parameterType(0).isAssignableFrom(exType)) throw newIllegalArgumentException("handler does not accept exception type "+exType); if (htype.returnType() != ttype.returnType()) throw misMatchedTypes("target and handler return types", ttype, htype);
< prev index next >