False positive java:S1874

  • SonarQube - 10.7, Scanner - 6.2.0.4584, Plugin - sonar-java-plugin-8.4.0.37032
  • deployed: zip

As a result of the project scan, we found a false positive regarding the S1874 rule on the use of a deprecated method. We are using an updated method with a modified order of input parameters with the same name



.

Hey there.

I’ve moved your post to the section for reporting false-positives.

Please review this post:

And provide a text-based sample of code (no screenshots!) that reproduces the issue.

Is this code sample enough?

import org.springframework.jdbc.core.JdbcTemplate;
import static constant.Errors.ERROR_CODE_SUCCESS;
import static org.mockito.ArgumentMatchers.*;
import org.springframework.jdbc.core.RowMapper;

 @Test
    void testGetAppData() {
        String appId = "5d75e6a1-eab0-11ce-abkf-00505697ce8e";
        when(jdbcTemplate.queryForObject(
                eq(CALL_STR_GET_APP_DATA),
                (RowMapper<Object>) any(),
                eq(appId)
        )).thenReturn(expectedGetAppDataResponse);
    }

Code from JdbcTemplate

@Deprecated
	@Override
	@Nullable
	public <T> T queryForObject(String sql, @Nullable Object[] args, RowMapper<T> rowMapper) throws DataAccessException {
		List<T> results = query(sql, args, new RowMapperResultSetExtractor<>(rowMapper, 1));
		return DataAccessUtils.nullableSingleResult(results);
	}

	@Override
	@Nullable
	public <T> T queryForObject(String sql, RowMapper<T> rowMapper, @Nullable Object... args) throws DataAccessException {
		List<T> results = query(sql, args, new RowMapperResultSetExtractor<>(rowMapper, 1));
		return DataAccessUtils.nullableSingleResult(results);
	}

Hello there, I failed to reproduce the issue. I could not simply copy paste your example as there are some missing information. It would be great if you could provide a self-contained and compiling snippet of code that I could just copy paste.

What I tried is the following, in class B I have:

  public void deprecatedMethod(String sql, Object o, @Nullable Object... args){
    //do something
  }

  @Deprecated(since = "1.0", forRemoval = true)
  public void deprecatedMethod(String sql, @Nullable Object[] args, Object o){
    //do something
  }

Then in class A I do this:

  void foo() {
    B mocked = mock(B.class);
    mocked.deprecatedMethod("SELECT * FROM DUAL", (Object) any(), new Object());
  }

With this code I cannot get an issue raised.