diff --git a/apps/samples/3DViewer/src/main/java/com/javafx/experiments/importers/Importer3D.java b/apps/samples/3DViewer/src/main/java/com/javafx/experiments/importers/Importer3D.java index efae06596d9..cbee66cf84b 100644 --- a/apps/samples/3DViewer/src/main/java/com/javafx/experiments/importers/Importer3D.java +++ b/apps/samples/3DViewer/src/main/java/com/javafx/experiments/importers/Importer3D.java @@ -32,6 +32,7 @@ package com.javafx.experiments.importers; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.net.URLClassLoader; @@ -122,7 +123,7 @@ public static Pair loadIncludingAnimation(String fileUrl, boolean for (String name : names) { try { Class clazz = Class.forName(name); - Object obj = clazz.newInstance(); + Object obj = clazz.getDeclaredConstructor().newInstance(); if (obj instanceof Importer) { Importer plugin = (Importer) obj; if (plugin.isSupported(extension)) { @@ -131,7 +132,8 @@ public static Pair loadIncludingAnimation(String fileUrl, boolean break; } } - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException + | InvocationTargetException | NoSuchMethodException e) { // FAIL SILENTLY } } diff --git a/apps/samples/Ensemble8/src/app/java/ensemble/EmbeddedApplication.java b/apps/samples/Ensemble8/src/app/java/ensemble/EmbeddedApplication.java index 34e36a21a83..faea9555782 100644 --- a/apps/samples/Ensemble8/src/app/java/ensemble/EmbeddedApplication.java +++ b/apps/samples/Ensemble8/src/app/java/ensemble/EmbeddedApplication.java @@ -52,7 +52,7 @@ public static Node createApplication(String className) { // Class appClass = EmbeddedApplication.class.getClassLoader().loadClass(className); Class appClass = InterpolatorApp.class; System.out.println("appClass = " + appClass); - Application app = (Application)appClass.newInstance(); + Application app = (Application)appClass.getDeclaredConstructor().newInstance(); System.out.println("app = " + app); app.init(); app.start(TEMP_STAGE); diff --git a/apps/samples/Ensemble8/src/app/java/ensemble/SampleInfo.java b/apps/samples/Ensemble8/src/app/java/ensemble/SampleInfo.java index 74afe591668..eceddaeb441 100644 --- a/apps/samples/Ensemble8/src/app/java/ensemble/SampleInfo.java +++ b/apps/samples/Ensemble8/src/app/java/ensemble/SampleInfo.java @@ -191,7 +191,7 @@ public SampleRuntimeInfo buildSampleNode() { Method play = null; Method stop = null; Class clz = Class.forName(appClass); - final Object app = clz.newInstance(); + final Object app = clz.getDeclaredConstructor().newInstance(); Parent root = (Parent) clz.getMethod("createContent").invoke(app); for (Method m : clz.getMethods()) { diff --git a/apps/toys/DragDrop/src/dragdrop/Main.java b/apps/toys/DragDrop/src/dragdrop/Main.java index 2e6c32f70cb..d00d34c6118 100644 --- a/apps/toys/DragDrop/src/dragdrop/Main.java +++ b/apps/toys/DragDrop/src/dragdrop/Main.java @@ -82,7 +82,7 @@ private Node createLauncher(final String name, final Class app) { @Override public void handle(MouseEvent event) { Stage stage = new Stage(); try { - ((Application) app.newInstance()).start(stage); + ((Application) app.getDeclaredConstructor().newInstance()).start(stage); } catch (Exception e) { e.printStackTrace(); } diff --git a/apps/toys/TouchSuite/src/touchsuite/Main.java b/apps/toys/TouchSuite/src/touchsuite/Main.java index c2d149fbae7..548d0833ca9 100644 --- a/apps/toys/TouchSuite/src/touchsuite/Main.java +++ b/apps/toys/TouchSuite/src/touchsuite/Main.java @@ -93,7 +93,7 @@ private Node createLauncher(final String name, final Class app) { @Override public void handle(MouseEvent event) { Stage stage = new Stage(); try { - ((Application) app.newInstance()).start(stage); + ((Application) app.getDeclaredConstructor().newInstance()).start(stage); } catch (Exception e) { e.printStackTrace(); } @@ -187,7 +187,7 @@ public void show(final String name, final Class app, final String info) { Info.this.setVisible(false); Stage stage = new Stage(); try { - ((Application) app.newInstance()).start(stage); + ((Application) app.getDeclaredConstructor().newInstance()).start(stage); } catch (Exception e) { e.printStackTrace(); } diff --git a/modules/javafx.base/src/test/java/test/com/sun/javafx/event/EventDispatchChainTest.java b/modules/javafx.base/src/test/java/test/com/sun/javafx/event/EventDispatchChainTest.java index ad6cc8b8619..346c177915a 100644 --- a/modules/javafx.base/src/test/java/test/com/sun/javafx/event/EventDispatchChainTest.java +++ b/modules/javafx.base/src/test/java/test/com/sun/javafx/event/EventDispatchChainTest.java @@ -57,8 +57,8 @@ public static Collection data() { private EventDispatchChain eventDispatchChain; public EventDispatchChainTest(final Class chainClass) - throws InstantiationException, IllegalAccessException { - eventDispatchChain = chainClass.newInstance(); + throws Exception { + eventDispatchChain = chainClass.getDeclaredConstructor().newInstance(); } @Test diff --git a/modules/javafx.base/src/test/java/test/javafx/util/converter/ParameterizedConverterTest.java b/modules/javafx.base/src/test/java/test/javafx/util/converter/ParameterizedConverterTest.java index b44337fc5ae..744b0c70858 100644 --- a/modules/javafx.base/src/test/java/test/javafx/util/converter/ParameterizedConverterTest.java +++ b/modules/javafx.base/src/test/java/test/javafx/util/converter/ParameterizedConverterTest.java @@ -93,7 +93,7 @@ public ParameterizedConverterTest(Class converterClas @Before public void setup() { try { - converter = converterClass.newInstance(); + converter = converterClass.getDeclaredConstructor().newInstance(); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/modules/javafx.controls/src/test/java/test/javafx/scene/control/CellTest.java b/modules/javafx.controls/src/test/java/test/javafx/scene/control/CellTest.java index 5dd50c1ad83..92f5e1520ae 100644 --- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/CellTest.java +++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/CellTest.java @@ -79,7 +79,7 @@ public CellTest(Class type) { } @Before public void setup() throws Exception { - cell = (Cell) type.newInstance(); + cell = (Cell) type.getDeclaredConstructor().newInstance(); // Empty TableCells can be selected, as long as the row they exist in // is not empty, so here we set a TableRow to ensure testing works diff --git a/modules/javafx.controls/src/test/java/test/javafx/scene/control/ControlTest.java b/modules/javafx.controls/src/test/java/test/javafx/scene/control/ControlTest.java index 07345e3b4aa..4558c272206 100644 --- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/ControlTest.java +++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/ControlTest.java @@ -1022,10 +1022,8 @@ private static void checkClass(Class someClass) { String what = someClass.getName(); try { // should get NoSuchMethodException if ctor is not public -// Constructor ctor = someClass.getConstructor((Class[])null); Method m = someClass.getMethod("getClassCssMetaData", (Class[]) null); -// Node node = (Node)ctor.newInstance((Object[])null); - Node node = (Node)someClass.newInstance(); + Node node = (Node)someClass.getDeclaredConstructor().newInstance(); for (CssMetaData styleable : (List>) m.invoke(null)) { what = someClass.getName() + " " + styleable.getProperty(); @@ -1033,7 +1031,7 @@ private static void checkClass(Class someClass) { assertNotNull(what, writable); Object defaultValue = writable.getValue(); - Object initialValue = styleable.getInitialValue((Node) someClass.newInstance()); + Object initialValue = styleable.getInitialValue((Node) someClass.getDeclaredConstructor().newInstance()); if (defaultValue instanceof Number) { // 5 and 5.0 are not the same according to equals, diff --git a/modules/javafx.controls/src/test/java/test/javafx/scene/control/EventAnyTest.java b/modules/javafx.controls/src/test/java/test/javafx/scene/control/EventAnyTest.java index 7eca74a3325..45b400cea2b 100644 --- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/EventAnyTest.java +++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/EventAnyTest.java @@ -92,7 +92,7 @@ public EventAnyTest(EventType type, Event event, Class target, boolean matches) @Test public void testEventDelivery() throws Exception { - Node n = (Node) target.newInstance(); + Node n = (Node) target.getDeclaredConstructor().newInstance(); delivered = false; n.addEventHandler(type, event1 -> { diff --git a/modules/javafx.controls/src/test/java/test/javafx/scene/control/FireButtonBaseTest.java b/modules/javafx.controls/src/test/java/test/javafx/scene/control/FireButtonBaseTest.java index bf8f0575300..13fcf98ed3b 100644 --- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/FireButtonBaseTest.java +++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/FireButtonBaseTest.java @@ -70,7 +70,7 @@ public FireButtonBaseTest(Class type) { } @Before public void setup() throws Exception { - btn = (ButtonBase) type.newInstance(); + btn = (ButtonBase) type.getDeclaredConstructor().newInstance(); } @Test public void onActionCalledWhenButtonIsFired() { diff --git a/modules/javafx.controls/src/test/java/test/javafx/scene/control/TextInputControlTest.java b/modules/javafx.controls/src/test/java/test/javafx/scene/control/TextInputControlTest.java index dbd93324499..8f9c73f7ecd 100644 --- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/TextInputControlTest.java +++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/TextInputControlTest.java @@ -86,7 +86,7 @@ public TextInputControlTest(Class type) { } @Before public void setup() throws Exception { - textInput = (TextInputControl) type.newInstance(); + textInput = (TextInputControl) type.getDeclaredConstructor().newInstance(); setUncaughtExceptionHandler(); } diff --git a/modules/javafx.controls/src/test/java/test/javafx/scene/control/cell/ParameterisedPrebuiltCellTest.java b/modules/javafx.controls/src/test/java/test/javafx/scene/control/cell/ParameterisedPrebuiltCellTest.java index a9e82644844..490dc3868c6 100644 --- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/cell/ParameterisedPrebuiltCellTest.java +++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/cell/ParameterisedPrebuiltCellTest.java @@ -65,16 +65,9 @@ public ParameterisedPrebuiltCellTest(Class cellClass) { this.cellClass = cellClass; } - @Before public void setup() { + @Before public void setup() throws Exception { count = 0; - - try { - cell = cellClass.newInstance(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } + cell = cellClass.getDeclaredConstructor().newInstance(); } diff --git a/modules/javafx.fxml/src/main/java/javafx/fxml/FXMLLoader.java b/modules/javafx.fxml/src/main/java/javafx/fxml/FXMLLoader.java index 7ab2a6e7fbc..0e8100c3fc0 100644 --- a/modules/javafx.fxml/src/main/java/javafx/fxml/FXMLLoader.java +++ b/modules/javafx.fxml/src/main/java/javafx/fxml/FXMLLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2021, 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 @@ -935,14 +935,12 @@ public void processAttribute(String prefix, String localName, String value) try { if (controllerFactory == null) { ReflectUtil.checkPackageAccess(type); - setController(type.newInstance()); + setController(type.getDeclaredConstructor().newInstance()); } else { setController(controllerFactory.call(type)); } - } catch (InstantiationException exception) { - throw constructLoadException(exception); - } catch (IllegalAccessException exception) { - throw constructLoadException(exception); + } catch (Exception e) { + throw constructLoadException(e); } } } else { @@ -1018,11 +1016,9 @@ public Object constructValue() throws IOException { if (value == null) { try { ReflectUtil.checkPackageAccess(type); - value = type.newInstance(); - } catch (InstantiationException exception) { - throw constructLoadException(exception); - } catch (IllegalAccessException exception) { - throw constructLoadException(exception); + value = type.getDeclaredConstructor().newInstance(); + } catch (Exception e) { + throw constructLoadException(e); } } } @@ -1328,11 +1324,9 @@ public Object constructValue() throws LoadException { if (value == null) { try { ReflectUtil.checkPackageAccess(type); - value = type.newInstance(); - } catch (InstantiationException exception) { - throw constructLoadException(exception); - } catch (IllegalAccessException exception) { - throw constructLoadException(exception); + value = type.getDeclaredConstructor().newInstance(); + } catch (Exception e) { + throw constructLoadException(e); } } root = value; diff --git a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/PlatformFactory.java b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/PlatformFactory.java index 82ff3519546..f7ad97b3b77 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/PlatformFactory.java +++ b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/PlatformFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2021, 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 @@ -40,7 +40,7 @@ public static synchronized PlatformFactory getPlatformFactory() { String factory = "com.sun.glass.ui." + platform.toLowerCase(Locale.ROOT) + "."+ platform + "PlatformFactory"; // System.out.println("Loading Glass Factory " + factory); Class c = Class.forName(factory); - instance = (PlatformFactory) c.newInstance(); + instance = (PlatformFactory) c.getDeclaredConstructor().newInstance(); } catch (Exception e) { e.printStackTrace(); System.out.println("Failed to load Glass factory class"); diff --git a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatformFactory.java b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatformFactory.java index be4d9059cbd..a960ec1167d 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatformFactory.java +++ b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatformFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021, 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 @@ -105,7 +105,7 @@ public static synchronized NativePlatform getNativePlatform() { throw new IllegalArgumentException("Unrecognized Monocle platform: " + factoryClassName); } - NativePlatformFactory npf = (NativePlatformFactory) clazz.newInstance(); + NativePlatformFactory npf = (NativePlatformFactory) clazz.getDeclaredConstructor().newInstance(); if (npf.matches() && npf.getMajorVersion() == majorVersion && npf.getMinorVersion() == minorVersion) { diff --git a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/TouchPipeline.java b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/TouchPipeline.java index 6b3da8d5ac5..22aac53549f 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/TouchPipeline.java +++ b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/TouchPipeline.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2021, 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 @@ -73,7 +73,7 @@ void addNamedFilter(String filterName) { + filterName + "TouchFilter"; } ClassLoader loader = Thread.currentThread().getContextClassLoader(); - addFilter((TouchFilter) loader.loadClass(filterName).newInstance()); + addFilter((TouchFilter) loader.loadClass(filterName).getDeclaredConstructor().newInstance()); } } catch (Exception e) { System.err.println( diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java index 829bc9a441e..1ea650f0bdb 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2021, 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 @@ -258,7 +258,7 @@ public static synchronized Toolkit getToolkit() { + forcedToolkit); } - TOOLKIT = (Toolkit)clz.newInstance(); + TOOLKIT = (Toolkit)clz.getDeclaredConstructor().newInstance(); if (TOOLKIT.init()) { if (printToolkit) { System.err.println("JavaFX: using " + forcedToolkit); diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLFactory.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLFactory.java index 36e74bbfbfc..d29fa2846ec 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLFactory.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -96,7 +96,7 @@ private static class FactoryLoader implements PrivilegedAction { public GLFactory run() { GLFactory factory = null; try { - factory = (GLFactory) Class.forName(factoryClassName).newInstance(); + factory = (GLFactory) Class.forName(factoryClassName).getDeclaredConstructor().newInstance(); } catch (Throwable t) { System.err.println("GLFactory.static - Platform: " + System.getProperty("os.name") diff --git a/modules/javafx.graphics/src/main/java/com/sun/scenario/effect/impl/prism/ps/PPSRenderer.java b/modules/javafx.graphics/src/main/java/com/sun/scenario/effect/impl/prism/ps/PPSRenderer.java index 55947b359a2..9daacbce017 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/scenario/effect/impl/prism/ps/PPSRenderer.java +++ b/modules/javafx.graphics/src/main/java/com/sun/scenario/effect/impl/prism/ps/PPSRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2021, 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 @@ -450,7 +450,7 @@ private static ShaderSource createShaderSource(String name) { Class klass = null; try { klass = Class.forName(name); - return (ShaderSource)klass.newInstance(); + return (ShaderSource)klass.getDeclaredConstructor().newInstance(); } catch (ClassNotFoundException e) { System.err.println(name + " class not found"); return null; diff --git a/modules/javafx.graphics/src/main/java/com/sun/scenario/effect/impl/prism/sw/PSWRenderer.java b/modules/javafx.graphics/src/main/java/com/sun/scenario/effect/impl/prism/sw/PSWRenderer.java index cdd8918de0e..bda50667545 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/scenario/effect/impl/prism/sw/PSWRenderer.java +++ b/modules/javafx.graphics/src/main/java/com/sun/scenario/effect/impl/prism/sw/PSWRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2021, 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 @@ -89,7 +89,7 @@ public synchronized static PSWRenderer createJSWInstance(Screen screen) { PSWRenderer ret = null; try { Class klass = Class.forName(rootPkg + ".impl.sw.java.JSWRendererDelegate"); - RendererDelegate delegate = (RendererDelegate)klass.newInstance(); + RendererDelegate delegate = (RendererDelegate)klass.getDeclaredConstructor().newInstance(); ret = new PSWRenderer(screen, delegate); } catch (Throwable e) {} return ret; @@ -104,7 +104,7 @@ public synchronized static PSWRenderer createJSWInstance(ResourceFactory factory PSWRenderer ret = null; try { Class klass = Class.forName(rootPkg + ".impl.sw.java.JSWRendererDelegate"); - RendererDelegate delegate = (RendererDelegate)klass.newInstance(); + RendererDelegate delegate = (RendererDelegate)klass.getDeclaredConstructor().newInstance(); ret = new PSWRenderer(factory, delegate); } catch (Throwable e) {} return ret; @@ -128,7 +128,7 @@ private synchronized static PSWRenderer createSSEInstance(Screen screen) { PSWRenderer ret = null; try { Class klass = Class.forName(rootPkg + ".impl.sw.sse.SSERendererDelegate"); - RendererDelegate delegate = (RendererDelegate)klass.newInstance(); + RendererDelegate delegate = (RendererDelegate)klass.getDeclaredConstructor().newInstance(); ret = new PSWRenderer(screen, delegate); } catch (Throwable e) {} return ret; diff --git a/modules/javafx.graphics/src/test/java/test/com/sun/javafx/test/OnInvalidateMethodsTestBase.java b/modules/javafx.graphics/src/test/java/test/com/sun/javafx/test/OnInvalidateMethodsTestBase.java index 1fbdd0cde1c..f1a5ba7a76a 100644 --- a/modules/javafx.graphics/src/test/java/test/com/sun/javafx/test/OnInvalidateMethodsTestBase.java +++ b/modules/javafx.graphics/src/test/java/test/com/sun/javafx/test/OnInvalidateMethodsTestBase.java @@ -79,21 +79,21 @@ public void testFireOnInvalidate() throws Exception { sb.setCharAt(0, Character.toUpperCase(propertyName.charAt(0))); if (clazz.getSuperclass().equals(PathElement.class)) { - PathElement e = (PathElement)clazz.newInstance(); + PathElement e = (PathElement)clazz.getDeclaredConstructor().newInstance(); Path path = new Path(); path.getElements().addAll(new MoveTo(0,0), e); NodeTest.syncNode(path); getSetter(clazz, sb.toString()).invoke(e, this.inValue); assertTrue(NodeTest.isDirty(path, (DirtyBits[])this.expectedDirtyBits)); } else if (clazz.getSuperclass().equals(Transform.class)) { - Transform tr = (Transform)clazz.newInstance(); + Transform tr = (Transform)clazz.getDeclaredConstructor().newInstance(); Rectangle rect = new Rectangle(); rect.getTransforms().add(tr); NodeTest.syncNode(rect); getSetter(clazz, sb.toString()).invoke(tr, this.inValue); assertTrue(NodeTest.isDirty(rect, (DirtyBits[])this.expectedDirtyBits)); } else { - Node node = (Node)clazz.newInstance(); + Node node = (Node)clazz.getDeclaredConstructor().newInstance(); NodeTest.syncNode(node); getSetter(clazz, sb.toString()).invoke(node, this.inValue); if (this.expectedDirtyBits instanceof DirtyBits[]) { @@ -109,7 +109,7 @@ public void testFireOnInvalidate() throws Exception { private Path getPathNode(Class pathElementClazz) throws Exception { Path p = new Path(); - p.getElements().addAll(new MoveTo(0,0), pathElementClazz.newInstance()); + p.getElements().addAll(new MoveTo(0,0), pathElementClazz.getDeclaredConstructor().newInstance()); return p; } diff --git a/modules/javafx.graphics/src/test/java/test/com/sun/javafx/test/binding/ReflectionHelper.java b/modules/javafx.graphics/src/test/java/test/com/sun/javafx/test/binding/ReflectionHelper.java index 7a7df49d2c9..416075e17bc 100644 --- a/modules/javafx.graphics/src/test/java/test/com/sun/javafx/test/binding/ReflectionHelper.java +++ b/modules/javafx.graphics/src/test/java/test/com/sun/javafx/test/binding/ReflectionHelper.java @@ -42,10 +42,10 @@ public static Class classForName(final String className) { public static Object newInstance(final Class cls) { try { - return cls.newInstance(); - } catch (final InstantiationException e) { - throw convertToRuntimeException(e); - } catch (final IllegalAccessException e) { + return cls.getDeclaredConstructor().newInstance(); + } catch (final RuntimeException e) { + throw e; + } catch (final Exception e) { throw convertToRuntimeException(e); } } diff --git a/modules/javafx.graphics/src/test/java/test/javafx/css/CssMetaDataTest.java b/modules/javafx.graphics/src/test/java/test/javafx/css/CssMetaDataTest.java index 5e3b08b3e84..60a9bd93e6f 100644 --- a/modules/javafx.graphics/src/test/java/test/javafx/css/CssMetaDataTest.java +++ b/modules/javafx.graphics/src/test/java/test/javafx/css/CssMetaDataTest.java @@ -1167,10 +1167,8 @@ private static void checkClass(Class someClass) { String what = someClass.getName(); try { // should get NoSuchMethodException if ctor is not public - // Constructor ctor = someClass.getConstructor((Class[])null); Method m = someClass.getMethod("getClassCssMetaData", (Class[]) null); - // Node node = (Node)ctor.newInstance((Object[])null); - Node node = (Node)someClass.newInstance(); + Node node = (Node)someClass.getDeclaredConstructor().newInstance(); List> list = (List>)m.invoke(null); if(list == null || list.isEmpty()) return; @@ -1181,7 +1179,7 @@ private static void checkClass(Class someClass) { assertNotNull(what, writable); Object defaultValue = writable.getValue(); - Object initialValue = styleable.getInitialValue((Node) someClass.newInstance()); + Object initialValue = styleable.getInitialValue((Node) someClass.getDeclaredConstructor().newInstance()); if (defaultValue instanceof Number) { // 5 and 5.0 are not the same according to equals, diff --git a/modules/javafx.graphics/src/test/java/test/javafx/scene/effect/EffectInputTest.java b/modules/javafx.graphics/src/test/java/test/javafx/scene/effect/EffectInputTest.java index 9635b74d53a..bda0d73473e 100644 --- a/modules/javafx.graphics/src/test/java/test/javafx/scene/effect/EffectInputTest.java +++ b/modules/javafx.graphics/src/test/java/test/javafx/scene/effect/EffectInputTest.java @@ -113,8 +113,8 @@ public void testInput() throws Exception { final Class effect1Class = Class.forName("javafx.scene.effect." + effect1Name); final Class effect2Class = Class.forName("javafx.scene.effect." + effect2Name); - Effect effect1 = (Effect) effect1Class.newInstance(); - Effect effect2 = (Effect) effect2Class.newInstance(); + Effect effect1 = (Effect) effect1Class.getDeclaredConstructor().newInstance(); + Effect effect2 = (Effect) effect2Class.getDeclaredConstructor().newInstance(); final Method getInput1 = effect1Class.getMethod("getInput"); final Method setInput1 = effect1Class.getMethod("setInput", Effect.class); final Method getInput2 = effect2Class.getMethod("getInput"); @@ -158,8 +158,8 @@ public void testCycle() throws Exception { final Class effect1Class = Class.forName("javafx.scene.effect." + effect1Name); final Class effect2Class = Class.forName("javafx.scene.effect." + effect2Name); - Effect effect1 = (Effect) effect1Class.newInstance(); - Effect effect2 = (Effect) effect2Class.newInstance(); + Effect effect1 = (Effect) effect1Class.getDeclaredConstructor().newInstance(); + Effect effect2 = (Effect) effect2Class.getDeclaredConstructor().newInstance(); final Method getInput1 = effect1Class.getMethod("getInput"); final Method setInput1 = effect1Class.getMethod("setInput", Effect.class); final Method getInput2 = effect2Class.getMethod("getInput"); @@ -198,8 +198,8 @@ public void testCycleForBoundInput() throws Exception { final Class effect1Class = Class.forName("javafx.scene.effect." + effect1Name); final Class effect2Class = Class.forName("javafx.scene.effect." + effect2Name); - Effect effect1 = (Effect) effect1Class.newInstance(); - Effect effect2 = (Effect) effect2Class.newInstance(); + Effect effect1 = (Effect) effect1Class.getDeclaredConstructor().newInstance(); + Effect effect2 = (Effect) effect2Class.getDeclaredConstructor().newInstance(); final Method getInput1 = effect1Class.getMethod("getInput"); final Method setInput2 = effect2Class.getMethod("setInput", Effect.class);