Avoid deprecated Class.newInstance in favor of constructor-based instantiation [SPR-14486] #19055
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Juergen Hoeller opened SPR-14486 and commented
As of JDK 9,
Class.newInstance()
is deprecated in favor ofConstructor.newInstance()
, with the latter throwingInvocationTargetException
instead of simply propagating user exceptions to the caller. Let's use this as an opportunity to revise our remaining use ofClass.newInstance()
, in particular our remaining use ofBeanUtils.instantiate(Class)
which is based on it (in contrast toBeanUtils.instantiateClass(Class
which explicitly uses the default constructor).Along the same line,
Proxy.getProxyClass
andXMLReaderFactory.createXMLReader
are in JDK 9 now as well. While we have no immediate replacement for those yet, we seem to be able to keep using them under our conditions (within the sameClassLoader
). Those spots need to be marked as@SuppressWarnings("deprecated")
though in order for our build to work on JDK 9 (with-Werror
).Issue Links:
The text was updated successfully, but these errors were encountered: