-
Enhancement
-
Resolution: Fixed
-
P4
-
7
-
b118
-
x86
-
linux
Please, deprecate Class.newInstance in JDK7 and add alternative method newObjectInstance which will declare exception correctly.
(or by wrapping exception or by adding generic throws clause)
JUSTIFICATION :
Class.newInstance violate checked exception definition.
It's' allows undeclared checked excetion to be actually throwed, which is in contradiction with rules of language and cause errors.
See also comments to
See also http://bugs.sun.com/view_bug.do?bug_id=5066799
related bugs:
http://bugs.sun.com/view_bug.do?bug_id=6195208
http://bugs.sun.com/view_bug.do?bug_id=4233093
they 'fixed' by specifing fundamentally incorrect behaviour in documentation, which is not fix of problem.
---------- BEGIN SOURCE ----------
next code frtagment
>>public class X
>> {
>>
>> public X() throws Exception
>> {
>> throw new Exception("hi!");
>> }
>>
>> public static void f() {
>> try {
>> X x = X.class.newInstance();
>> } catch (InstantiationException ex) {
>> System.err.println("instantiation exception");
>> ex.printStackTrace();
>> } catch (IllegalAccessException ex) {
>> System.err.println("illegal access exception");
>> ex.printStackTrace();
>> }
>> }
>>
>> }
>>
will throw checked exception X from function X.f(), which is not declare one.
---------- END SOURCE ----------
- csr of
-
CCC-6850612 Deprecate Class.newInstance since it violates the checked exception language contract
- Closed
- relates to
-
JDK-8155963 Fix deprecation warning in windows java.net implementation
- Closed
-
JDK-8155873 Fix deprecation warnings about Class.newInstance
- Open
-
JDK-8065614 JEP 277: Enhanced Deprecation
- Closed
-
JDK-8283146 Example in 4.3.1 uses deprecated API
- Closed
-
JDK-8157055 consider unified release notes for deprecated APIs
- Closed
-
JDK-8233837 getConstructor() not working as expected
- Closed
-
JDK-8280602 4.3.1: Avoid use of newInstance when it is terminally deprecated
- Open