public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: mauve-patches@sources.redhat.com
Subject: FYI: Add extra Class.newInstance() checks
Date: Sun, 25 Jun 2006 16:55:00 -0000	[thread overview]
Message-ID: <1151254521.8131.6.camel@hermans.wildebeest.org> (raw)

[-- 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)

                 reply	other threads:[~2006-06-25 16:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1151254521.8131.6.camel@hermans.wildebeest.org \
    --to=mark@klomp.org \
    --cc=mauve-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).