Bug 112914 - Load-time weaving only works with a 1.5 JRE
Summary: Load-time weaving only works with a 1.5 JRE
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-18 05:49 EDT by Sian January CLA
Modified: 2005-11-08 06:00 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sian January CLA 2005-10-18 05:49:50 EDT
AJDT uses the WeavingURLClassLoader to enable load-time weaving in Eclipse.  
If the projects that the user is attempting to load-time weave refer to a 1.4 
version of the JRE the following exception occurs:

warning Register definition failed -- (SAXException) System property 
org.xml.sax.driver not specified
System property org.xml.sax.driver not specified
org.xml.sax.SAXException: System property org.xml.sax.driver not specified
	at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)
	at org.aspectj.weaver.loadtime.definition.DocumentParser.parse
(DocumentParser.java:80)
	at 
org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.registerDefinitions
(ClassLoaderWeavingAdaptor.java:148)
	at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.initialize
(ClassLoaderWeavingAdaptor.java:109)
	at org.aspectj.weaver.loadtime.WeavingURLClassLoader.defineClass
(WeavingURLClassLoader.java:106)
	at org.aspectj.weaver.ExtensibleURLClassLoader.defineClass
(ExtensibleURLClassLoader.java:80)
	at org.aspectj.weaver.ExtensibleURLClassLoader.findClass
(ExtensibleURLClassLoader.java:46)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Comment 1 Matthew Webster CLA 2005-10-19 18:10:05 EDT
Try -Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser
Comment 2 Sian January CLA 2005-10-25 05:44:03 EDT
Unfortunately the SAXParser class isn't there in the 1.4 library and I 
couldn't find a suitable replacement.  I wondered whether it might be possible 
to change the use of the SAXParser to use a DocumentBuilder instead.  E.g. to 
read an XML file into an org.w3c.dom.Document do the following:

InputStream fileContents = .....
DocumentBuilder builder = DocumentBuilderFactory.newInstance
().newDocumentBuilder();
builder.setErrorHandler(new AOPXMLErrorHandler());
Document document = builder.parse(fileContents);	


AOPXMLErrorHandler might look like this:

	/**
	 * Error handler class for AOP XML parsing exceptions
	 */
	private static class AOPXMLErrorHandler extends DefaultHandler {
		
		/**
		 * Throws a more detailed exception when an error occurs 
parsing a file.
		 * @param exception - the Exception input
		 * @throws SAXException - more detained Exception
		 * @see org.xml.sax.ErrorHandler#error
(org.xml.sax.SAXParseException)
		 */
		public void error(SAXParseException exception) throws 
SAXException {
			throw new AOPXMLException(
				"A problem occurred parsing aop.xml file " //
$NON-NLS-1$
					+ exception.getSystemId().substring(
						exception.getSystemId().indexOf
("file:///") + 8) //$NON-NLS-1$
					+ "[" //$NON-NLS-1$
					+ exception.getLineNumber()
					+ "," //$NON-NLS-1$
					+ exception.getColumnNumber()
					+ "]"  //$NON-NLS-1$
					+ System.getProperty
("line.separator") //$NON-NLS-1$
					+ exception.getMessage().substring(
						exception.getMessage().indexOf
(':') + 2));
		}
		
		
		/**
		 * Throws a more detailed exception when a warning occurs while
		 * parsing a file
		 * @param exception - inout
		 * @throws SAXException - more detailed output
		 * @see org.xml.sax.ErrorHandler#warning
(org.xml.sax.SAXParseException)
		 */
		public void warning(SAXParseException exception) throws 
SAXException {
			error(exception);
		}

		
		/**
		 * Throws a more detailed exception when a fatal error occurs 
while
		 * parsing a file 
		 * @param exception - input
		 * @throws SAXException - more detailed output
		 * @see org.xml.sax.ErrorHandler#fatalError
(org.xml.sax.SAXParseException)
		 */
		public void fatalError(SAXParseException exception) throws 
SAXException	{
			error(exception);
		}
				
	}


These snippets are taken from org.eclipse.ajdt.internal.launching.LTWUtils in 
the AJDT UI plug-in.
Comment 3 Alexandre Vasseur CLA 2005-10-25 05:53:38 EDT
can' t we package Xerces from Apache website ?

I am not sure about the DOM API you suggest but I think you 'll have the same
issue ie using DOM will require a DOM implementation as well (and even more
probably a SAX one as well as lower layer)


Comment 4 Andrew Clement CLA 2005-10-28 09:49:38 EDT
Andy to discuss with Sian.
Comment 5 Andrew Clement CLA 2005-11-03 08:52:58 EST
Ok, had a discussion on this.  I really don't want to get into shipping a copy
of xerces.jar.  The DocumentBuilder stuff Sian describes in her comment is in my
1.4 vm and my 1.5 vm.  Alex, is there a real problem with using this seemingly
common interface? (I'm not an XML parsing expert by any means...)

I don't mind asking command line compiler users to have an XML parser around
(although even that seems unfriendly if there is support in the base JDK) but we
can't expect AJDT users to conjure one up.  Eclipse used to ship xerces but
decided to get out of that game in the 3.0 timeframe.
Comment 6 Alexandre Vasseur CLA 2005-11-03 10:26:46 EST
can someone try with
            XMLReader xmlReader =
javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser().getXMLReader();
// XMLReaderFactory.createXMLReader();

in DocumentParser:81

I don't want to use DOM (unless we want to have yet more memory for LTW)
Comment 7 Andrew Clement CLA 2005-11-07 08:14:58 EST
I tried:

 XMLReader xmlReader =
javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser().getXMLReader();

and it works fine (as far as I can tell).

Shall I change it Alex?
Comment 8 Alexandre Vasseur CLA 2005-11-07 09:50:32 EST
sure go ahead
this looks like this one will use the bundled factory or something
Comment 9 Andrew Clement CLA 2005-11-07 10:06:12 EST
change committed. will wait for Sian to confirm its ok with Eclipse 3.0 before
closing.
Comment 10 Andrew Clement CLA 2005-11-08 06:00:13 EST
Sian confirmed the fix is OK for Eclipse 3.0 users.  Closing this bug.