Buggy code:
public class JPQLExpressionBuilder extends AbstractExpressionBuilder implements JPQLTreeConstants { private static final int VAR_PATH = 1 ; private static final int VAR_ERROR = 2 ; private static final Localizer _loc = Localizer . forPackage ( JPQLExpressionBuilder . class ) ; private final Stack contexts = new Stack ( ) ; private LinkedMap parameterTypes ; private int aliasCount = 0 ; public JPQLExpressionBuilder ( ExpressionFactory factory , ExpressionStoreQuery query , Object parsedQuery ) { } protected Localizer getLocalizer ( ) { } protected ClassLoader getClassLoader ( ) { } protected JPQLExpressionBuilder . ParsedJPQL getParsedQuery ( ) { } protected JPQLExpressionBuilder . ParsedJPQL getParsedQuery ( String jpql ) { } private void setCandidate ( ClassMetaData cmd , String schemaAlias ) { } private String nextAlias ( ) { } protected ClassMetaData resolveClassMetaData ( JPQLExpressionBuilder . JPQLNode node ) { } private ClassMetaData getClassMetaData ( String alias , boolean assertValid ) { } private Class getCandidateType ( ) { } private ClassMetaData getCandidateMetaData ( ) { } protected ClassMetaData getCandidateMetaData ( JPQLExpressionBuilder . JPQLNode node ) { } protected String currentQuery ( ) { } QueryExpressions getQueryExpressions ( ) { } private Expression and ( Expression e1 , Expression e2 ) { } private static String assemble ( JPQLExpressionBuilder . JPQLNode node ) { } private static String assemble ( JPQLExpressionBuilder . JPQLNode node , String delimiter , int last ) { } private Expression assignProjections ( JPQLExpressionBuilder . JPQLNode parametersNode , QueryExpressions exps ) { } private void evalQueryOperation ( QueryExpressions exps ) { } private void evalGroupingClause ( QueryExpressions exps ) { } private void evalHavingClause ( QueryExpressions exps ) { } private void evalOrderingClauses ( QueryExpressions exps ) { } private Expression evalSelectClause ( QueryExpressions exps ) { } private String assertSchemaAlias ( ) { } protected Expression evalFetchJoins ( QueryExpressions exps ) { } protected void evalSetClause ( QueryExpressions exps ) { } private Expression evalWhereClause ( ) { } private Expression evalFromClause ( boolean needsAlias ) { } private Expression addJoin ( JPQLExpressionBuilder . JPQLNode node , boolean inner , Expression exp ) { } private Expression addJoin ( Path path , JPQLExpressionBuilder . JPQLNode aliasNode , Expression exp ) { } private Expression evalFromItem ( Expression exp , JPQLExpressionBuilder . JPQLNode node , boolean needsAlias ) { } protected boolean isDeclaredVariable ( String name ) { } boolean isPath ( JPQLExpressionBuilder . JPQLNode node ) { } private static ClassMetaData getFieldType ( FieldMetaData fmd ) { } protected Value getVariable ( String id , boolean bind ) { } protected boolean isSeendVariable ( String id ) { } private String assertSchemaName ( JPQLExpressionBuilder . JPQLNode node ) { } private Object eval ( JPQLExpressionBuilder . JPQLNode node ) { } private void assertQueryExtensions ( String clause ) { } protected void setImplicitTypes ( Value val1 , Value val2 , Class expected ) { super . setImplicitTypes ( val1 , val2 , expected ) ; Parameter param = ( val1 instanceof Parameter ) ? ( ( Parameter ) ( val1 ) ) : val2 instanceof Parameter ? ( ( Parameter ) ( val2 ) ) : null ; Path path = ( val1 instanceof Path ) ? ( ( Path ) ( val1 ) ) : val2 instanceof Path ? ( ( Path ) ( val2 ) ) : null ; if ( ( ( param == null ) || ( path == null ) ) || ( ( parameterTypes ) == null ) ) return ; FieldMetaData fmd = path . last ( ) ; if ( fmd == null ) return ; <START_BUG> Class type = ( path . isXPath ( ) ) ? path . getType ( ) : fmd . getType ( ) ; <END_BUG> if ( type == null ) return ; String paramName = param . getParameterName ( ) ; if ( paramName == null ) return ; if ( parameterTypes . containsKey ( paramName ) ) parameterTypes . put ( paramName , type ) ; } private Value getStringValue ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getNumberValue ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getTypeValue ( JPQLExpressionBuilder . JPQLNode node , Class implicitType ) { } private Value getSubquery ( JPQLExpressionBuilder . JPQLNode node ) { } private Parameter getParameter ( String id , boolean positional ) { } private Expression evalNot ( boolean not , Expression exp ) { } private String trimQuotes ( String str ) { } private short negative ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getIdentifier ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getPathOrConstant ( JPQLExpressionBuilder . JPQLNode node ) { } private Path getPath ( JPQLExpressionBuilder . JPQLNode node ) { } private Path getPath ( JPQLExpressionBuilder . JPQLNode node , boolean pcOnly , boolean inner ) { } protected Class getDeclaredVariableType ( String name ) { } private Expression getExpression ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getValue ( JPQLExpressionBuilder . JPQLNode node ) { } private Path newPath ( Value val , ClassMetaData meta ) { } private Value getValue ( JPQLExpressionBuilder . JPQLNode node , int handleVar ) { } private JPQLExpressionBuilder . Context ctx ( ) { } private JPQLExpressionBuilder . JPQLNode root ( ) { } private ClassMetaData getMetaDataForAlias ( String alias ) { } private class Context { private final JPQLExpressionBuilder . ParsedJPQL parsed ; private ClassMetaData meta ; private String schemaAlias ; private Subquery subquery ; Context ( JPQLExpressionBuilder . ParsedJPQL parsed , Subquery subquery ) { } } private JPQLExpressionBuilder . JPQLNode onlyChild ( JPQLExpressionBuilder . JPQLNode node ) throws UserException { } private JPQLExpressionBuilder . JPQLNode left ( JPQLExpressionBuilder . JPQLNode node ) { } private JPQLExpressionBuilder . JPQLNode right ( JPQLExpressionBuilder . JPQLNode node ) { } private JPQLExpressionBuilder . JPQLNode child ( JPQLExpressionBuilder . JPQLNode node , int childNum , int assertCount ) { } private JPQLExpressionBuilder . JPQLNode firstChild ( JPQLExpressionBuilder . JPQLNode node ) { }

Fix:
Class type = ( path . isXPath ( ) ) ? path . getType ( ) : fmd . getDeclaredType ( ) ;