[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6165) HqlLexer can cause ClassNotFound in OSGi environment

Scott Marlow (JIRA) noreply at atlassian.com
Wed Aug 3 09:23:05 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6165?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43167#comment-43167 ] 

Scott Marlow commented on HHH-6165:
-----------------------------------

I like your patch but I did mine differently in HHH-6536.  One question that I have about your patch, can it be made to use an antlr api instead of referencing a protected variable directly?  Is the protected tokenObjectClass documented as being safe to change (in terms of future releases of antlr including the same variable)?

In my patch, I set the thread context classloader to HqlToken.class.getClassLoader().  Would that work for your case also?  

> HqlLexer can cause ClassNotFound in OSGi environment
> ----------------------------------------------------
>
>                 Key: HHH-6165
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6165
>             Project: Hibernate Core
>          Issue Type: Patch
>          Components: core
>    Affects Versions: 3.3.2, 3.5.0.Beta-1, 3.5.0-Beta-2, 3.5.0-Beta-3, 3.5.0-Beta-4, 3.5.0-CR-1, 3.5.0-CR-2, 3.5.0-Final, 3.5.1, 3.5.2, 3.5.3, 3.5.4, 3.6.0.Beta1, 3.6.0.Beta2, 3.5.5, 3.6.0.Beta3, 3.6.0.Beta4, 3.5.6, 3.6.0.CR1, 3.6.0.CR2, 3.6.0, 3.6.1, 3.6.2
>         Environment: At least from 3.3.2 on, and at least on Postgres and Derby
>            Reporter: Jonathan Calvert
>            Priority: Minor
>         Attachments: hqllexer.patch
>
>
> org.hibernate.hql.ast.HqlLexer can cause a ClassNotFound exception in an OSGi environment with a stacktrace like 
> {code}
> org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [hql query here]
> 	at org.hibernate.hql.ast.HqlLexer.panic(HqlLexer.java:80)
> 	at antlr.CharScanner.setTokenObjectClass(CharScanner.java:338)
> 	at org.hibernate.hql.ast.HqlLexer.setTokenObjectClass(HqlLexer.java:54)
>         ...
> {code}
> The HqlLexer class has antlr.CharScanner as a superclass, as evidenced by the stacktrace. The contents of the method are: 
> {code}
> public void setTokenObjectClass(String cl) {
> 		// Ignore the token class name parameter, and use a specific token class.
> 		super.setTokenObjectClass( HqlToken.class.getName() );
> 	}
> {code}
> It passes the name of the HqlToken class as a string to CharScanner, which then ultimately attempts to find HqlToken via antlr.Utils. The tokenObjectClass is a protected field. The code can be simplified by simply setting the field directly to HqlToken.class which is obviously already available to the HqlLexer class. 
> The reason this causes the exception in an OSGi environment is that the context class loader available to ANTLR is limited to what is explicitly declared in the ANTLR bundle. Since ANTLR cannot (and should not) have to know about all the classes that it may be passed, it does not declare an import on the org.hibernate.hql.ast package. By passing the class directly, the lookup is avoided from within the ANTLR package. 
> {code}
> public void setTokenObjectClass(String cl) {
> 		// Ignore the token class name parameter, and use a specific token class.
> 		tokenObjectClass = HqlToken.class;
> 	}
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list