Skip to content

Unexpected dead code warning. #4152

@RabbitSeries

Description

@RabbitSeries
SessionCallback<List<Object>> obj;

    public void method() throws TransactionException {
        StringRedisTemplate stringRedisTemplate = resourcePool.template();
        var res = obj.execute(stringRedisTemplate);// @Nullable <K, V> T execute(RedisOperations<K, V> operations) throws DataAccessException;
        if (res == null) {
            System.out.println("Direct execution is not Dead Code");
        }
        List<Object> results = stringRedisTemplate.execute(new SessionCallback<List<Object>>() {
            @Override
            @Nullable
            public <K, V> List<Object> execute(@NonNull RedisOperations<K, V> operations) throws DataAccessException {
                operations.multi();
                return null;
            }
        });
        // @Override public <T> T StringRedisTemplate::execute(SessionCallback<T> session) {
        // 	...
        // 	try {
        // 		return session.execute(this); -> this is NullAble
        // 	} finally {
        // 		RedisConnectionUtils.unbindConnection(factory);
        // 	}
        // }
        if (results == null) {
            throw new TransactionException("Transaction failed, please retry") {
            };
        }
    }
Image

Minimal reproduce repo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions