0

I am trying to get all log from svn repository using SVNKit. It is working fine, but saw an infer generic type argument warning message. I have tried to cast the line

repository.log(new String[]{""}, null, START_REVISION, HEAD_REVISION, true, true);

with

Collection<SVNLogEntry>

But warning is still there . Is it possible to remove this warning without suppressing it ?

    private Collection<SVNLogEntry> getAllSvnLogsFromStart_Revision()   {
    DAVRepositoryFactory.setup();
    SVNRepository repository = null;
    Collection<SVNLogEntry> logEntries = null;
    try {
        repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( SVN_URL ) );
        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(userName, passWord);
        repository.setAuthenticationManager(authManager);          
        logEntries = repository.log(new String[]{""}, null, START_REVISION, HEAD_REVISION, true, true);
    }catch (SVNException e) {
        e.printStackTrace();
    }
    return logEntries;
}

warning message


svnkit api

anirban
  • 674
  • 1
  • 7
  • 21

2 Answers2

2

Since SVNRepository.log() returns a raw Collection type you will have to deal with unchecked conversion. The cleanest way would be to minimize @SuppressWarnings field of effect by applying it to the variable declaration:

@SuppressWarnings("unchecked")
Collection<SVNLogEntry> logEntries = repository.log(new String[]{""}, null, START_REVISION, HEAD_REVISION, true, true);
return logEntries;
pingw33n
  • 12,292
  • 2
  • 37
  • 38
  • hi @pingw33n got your point, still my question is, are there any way to remove this warning without using suppresswarning? – anirban Jun 13 '14 at 11:06
1

The unchecked warning cannot be worked around with a direct conversion because Java can't statically define the type safety of the operation, as the content of the array is not know; the solution would be to make the content of the array known to java:

    Collection<SVNLogEntry> typesafe = new ArrayList<SVNLogEntry>();

    for (Object o : repository.log(new String[]{""}, null, START_REVISION, HEAD_REVISION, true, true)) {
        typesafe.add((SVNLogEntry)o);
    }

this comes with a performance penalty but allows the runtime to be sure of what the typed array content is and makes the warning disappear.

However, if you are looking for an alternative to suppress the warning without using SuppressWarning, there is this other route (which applies to the project as a whole, sadly):

To disable the warning without suppress warning, you have go to preferences, under java > compiler > error/warnings, where there is a Generic types fold containing these messages

warning configuration

putting them to ignore should also remove the tooltip.

Lorenzo Boccaccia
  • 6,041
  • 2
  • 19
  • 29