pramoth / specification-with-projection

Support projections with JpaSpecificationExecutor.findAll(Specification,Pageable) for Spring Data JPA
MIT License
164 stars 56 forks source link

NPE in Debug Mode #4

Open dengizik opened 6 years ago

dengizik commented 6 years ago

Hi,

first thanks for this nice implementation. I faced an issue and wanted to inform you about that.

In JpaSpecificationExecutorWithProjectionImpl:

private <R> Page<R> readPageWithProjection(Specification<T> spec, Class<R> projectionType, Pageable pageable, TypedQuery<T> query) {
        if (log.isDebugEnabled()) {
            query.getHints().forEach((key, value) -> {
                log.info("apply query hints -> {} : {}", key, value);
            });
        }

        Page<T> result = pageable == null ? new PageImpl(query.getResultList()) : this.readPage(query, this.getDomainClass(), pageable, spec);
        return ((Page)result).map((item) -> {
            return this.projectionFactory.createProjection(projectionType, item);
        });
    }

if (log.isDebugEnabled()) should be if (log.isDebugEnabled() && !query.getHints.isEmpty())

There is no logical relationship between being in debug mode and having queryhints, at least I don't know. If we leave the code like this, it throws NPE in debug mode. I solved the problem by going out of debug mode.

Regards, Deniz

pramoth commented 6 years ago

Can you contribute by fixed this issue and then pull request?