duplicate classes (SAX problem)

nferrier@tapsellferrier.co.uk nferrier@tapsellferrier.co.uk
Thu Oct 24 02:12:00 GMT 2002


The natClassLoader has this which checks for the existance of a class
before loading another class is allowed:

void
_Jv_RegisterClassHookDefault (jclass klass)
{
  jint hash = HASH_UTF (klass->name);

  jclass check_class = loaded_classes[hash];

  // If the class is already registered, don't re-register it.
  while (check_class != NULL)
    {
      if (check_class == klass)
	{
	  // If you get this, it means you have the same class in two
	  // different libraries.
#define TEXT "Duplicate class registration: "
	  // We size-limit MESSAGE so that you can't trash the stack.
	  char message[200];
	  strcpy (message, TEXT);
	  strncpy (message + sizeof (TEXT) - 1, klass->name->data,
		   sizeof (message) - sizeof (TEXT));
	  message[sizeof (message) - 1] = '\0';
	  if (! gcj::runtimeInitialized)
	    JvFail (message);
	  else
	    {
	      java::lang::String *str = JvNewStringLatin1 (message);
	      throw new java::lang::VirtualMachineError (str);
	    }
	}

      check_class = check_class->next;
    }

  klass->next = loaded_classes[hash];
  loaded_classes[hash] = klass;
}


Instead of throwing an exception shouldn't this somehow allow the use
of the existing (already loaded) class?


I'm wondering how anybody has got Tomcat or any of the other Apache
tools to run given that they mostly distribute the SAX classes
(because they all come with Xerces).


Nic



More information about the Java mailing list