* FYI: Add extra Class.newInstance() checks
@ 2006-06-25 16:55 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2006-06-25 16:55 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1: Type: text/plain, Size: 306 bytes --]
Hi,
This adds some tests to make sure that interface, abstract, primitive
and void classes cannot be instantiated.
2006-06-25 Mark Wielaard <mark@klomp.org>
* gnu/testlet/java/lang/Class/newInstance.java: Add checks for
interface, abstract, primitive and void classes.
Committed,
Mark
[-- Attachment #2: newInstance.patch --]
[-- Type: text/x-patch, Size: 2799 bytes --]
Index: gnu/testlet/java/lang/Class/newInstance.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/lang/Class/newInstance.java,v
retrieving revision 1.6
diff -u -r1.6 newInstance.java
--- gnu/testlet/java/lang/Class/newInstance.java 28 Feb 2006 18:31:31 -0000 1.6
+++ gnu/testlet/java/lang/Class/newInstance.java 25 Jun 2006 16:51:19 -0000
@@ -3,6 +3,7 @@
// Uses: pkg/test1 pkg/test2 pkg/test3 pkg/test4
// Copyright (C) 2005 Jeroen Frijters
+// Copyright (C) 2006 Mark J. Wielaard
// This file is part of Mauve.
@@ -198,6 +199,104 @@
}
test6.check(harness);
+
+ boolean thrown;
+ // Interfaces cannot be instantiated
+ try
+ {
+ Runnable.class.newInstance();
+ thrown = false;
+ }
+ catch (IllegalAccessException iae)
+ {
+ thrown = false; // Wrong one
+ }
+ catch (InstantiationException ie)
+ {
+ thrown = true;
+ }
+ harness.check(thrown);
+
+ // Abstract classes cannot be instantiated
+ try
+ {
+ Number.class.newInstance();
+ thrown = false;
+ }
+ catch (IllegalAccessException iae)
+ {
+ thrown = false; // Wrong one
+ }
+ catch (InstantiationException ie)
+ {
+ thrown = true;
+ }
+ harness.check(thrown);
+
+ // Array classes cannot be instantiated
+ try
+ {
+ new Object[1].getClass().newInstance();
+ thrown = false;
+ }
+ catch (IllegalAccessException iae)
+ {
+ thrown = false; // Wrong one
+ }
+ catch (InstantiationException ie)
+ {
+ thrown = true;
+ }
+ harness.check(thrown);
+
+ // Primitive classes cannot be instantiated
+ try
+ {
+ Byte.TYPE.newInstance();
+ thrown = false;
+ }
+ catch (IllegalAccessException iae)
+ {
+ thrown = false; // Wrong one
+ }
+ catch (InstantiationException ie)
+ {
+ thrown = true;
+ }
+ harness.check(thrown);
+
+ // Void cannot be instantiated
+ try
+ {
+ Void.TYPE.newInstance();
+ thrown = false;
+ }
+ catch (IllegalAccessException iae)
+ {
+ thrown = false; // Wrong one
+ }
+ catch (InstantiationException ie)
+ {
+ thrown = true;
+ }
+ harness.check(thrown);
+
+ // No nullary constructor cannot be instantiated
+ try
+ {
+ Integer.class.newInstance();
+ thrown = false;
+ }
+ catch (IllegalAccessException iae)
+ {
+ thrown = false; // Wrong one
+ }
+ catch (InstantiationException ie)
+ {
+ thrown = true;
+ }
+ harness.check(thrown);
+
}
static void checkSuccess(TestHarness harness, Class c)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-06-25 16:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-25 16:55 FYI: Add extra Class.newInstance() checks Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).