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 String projectionClause ( JPQLExpressionBuilder . JPQLNode node ) { } 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 . getDeclaredType ( ) ; <END_BUG> if ( type == null ) return ; Object paramKey = param . getParameterKey ( ) ; if ( paramKey == null ) return ; if ( parameterTypes . containsKey ( paramKey ) ) parameterTypes . put ( paramKey , 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 , boolean isCollectionValued ) { } 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 validateMapPath ( JPQLExpressionBuilder . JPQLNode node , JPQLExpressionBuilder . JPQLNode id ) { } private Value getGeneralIdentifier ( JPQLExpressionBuilder . JPQLNode node , boolean inWhereClause ) { } private Value getQualifiedIdentifier ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getQualifiedPath ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getQualifiedPath ( JPQLExpressionBuilder . JPQLNode node , boolean pcOnly , boolean inner ) { } private Value getTypeLiteral ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getPathOrConstant ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getType ( 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 getSimpleCaseExpression ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getGeneralCaseExpression ( JPQLExpressionBuilder . JPQLNode node ) { } private Expression getWhenCondition ( JPQLExpressionBuilder . JPQLNode node ) { } private Expression getWhenScalar ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getCoalesceExpression ( JPQLExpressionBuilder . JPQLNode node ) { } private Value getNullIfExpression ( JPQLExpressionBuilder . JPQLNode node ) { }

Fix:
Class type = path . getType ( ) ;