Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning messages when building JCommander #578

Open
jtilahun opened this issue Mar 11, 2024 · 3 comments
Open

Warning messages when building JCommander #578

jtilahun opened this issue Mar 11, 2024 · 3 comments

Comments

@jtilahun
Copy link

I'm observing the following warning messages when running Copybara (which depends on JCommander):

INFO: From Building external/JCommander/libjcommander.jar (61 source files):
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/DefaultUsageFormatter.java:217: warning: [unchecked] unchecked cast
                String valueList = EnumSet.allOf((Class<? extends Enum>) type).toString();
                                                                         ^
  required: Class<? extends Enum>
  found:    Class<CAP#1>
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object from capture of ?
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/DefaultUsageFormatter.java:217: warning: [unchecked] unchecked method invocation: method allOf in class EnumSet is applied to given types
                String valueList = EnumSet.allOf((Class<? extends Enum>) type).toString();
                                                ^
  required: Class<E>
  found: Class<CAP#1>
  where E is a type-variable:
    E extends Enum<E> declared in method <E>allOf(Class<E>)
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Enum from capture of ? extends Enum
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/JCommander.java:982: warning: [unchecked] unchecked conversion
            mainParameter.multipleValue = result;
                                          ^
  required: List<Object>
  found:    List
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/JCommander.java:1347: warning: [unchecked] unchecked call to isAssignableFrom(Class<?>) as a member of the raw type Class
        if (type.isAssignableFrom(List.class)) {
                                 ^
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/JCommander.java:1351: warning: [unchecked] unchecked call to isAssignableFrom(Class<?>) as a member of the raw type Class
        if (type.isAssignableFrom(List.class) && converter == null) {
                                 ^
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/JCommander.java:1354: warning: [unchecked] unchecked call to DefaultListConverter(IParameterSplitter,IStringConverter<T>) as a member of the raw type DefaultListConverter
            converter = new DefaultListConverter(splitter, new IStringConverter() {
                        ^
  where T is a type-variable:
    T extends Object declared in class DefaultListConverter
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/JCommander.java:1370: warning: [unchecked] unchecked call to EnumConverter(String,Class<T>) as a member of the raw type EnumConverter
            converter = new EnumConverter(optionName, type);
                        ^
  where T is a type-variable:
    T extends Enum<T> declared in class EnumConverter
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/JCommander.java:1394: warning: [unchecked] unchecked cast
        for (Constructor<T> c : (Constructor<T>[]) converterClass.getDeclaredConstructors()) {
                                                                                         ^
  required: Constructor<T>[]
  found:    Constructor<?>[]
  where T is a type-variable:
    T extends Object declared in method <T>instantiateConverter(String,Class<? extends T>)
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/ParameterDescription.java:264: warning: [unchecked] unchecked method invocation: method addAll in interface Collection is applied to given types
          l.addAll((Collection) convertedValue);
                  ^
  required: Collection<? extends E>
  found: Collection
  where E is a type-variable:
    E extends Object declared in interface Collection
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/ParameterDescription.java:264: warning: [unchecked] unchecked conversion
          l.addAll((Collection) convertedValue);
                   ^
  required: Collection<? extends E>
  found:    Collection
  where E is a type-variable:
    E extends Object declared in interface Collection
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/ParameterDescription.java:364: warning: [unchecked] unchecked call to validate(String,T) as a member of the raw type IValueValidator
      validator.newInstance().validate(name, value);
                                      ^
  where T is a type-variable:
    T extends Object declared in interface IValueValidator
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/UnixStyleUsageFormatter.java:91: warning: [unchecked] unchecked cast
                String valueList = EnumSet.allOf((Class<? extends Enum>) type).toString();
                                                                         ^
  required: Class<? extends Enum>
  found:    Class<CAP#1>
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object from capture of ?
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/UnixStyleUsageFormatter.java:91: warning: [unchecked] unchecked method invocation: method allOf in class EnumSet is applied to given types
                String valueList = EnumSet.allOf((Class<? extends Enum>) type).toString();
                                                ^
  required: Class<E>
  found: Class<CAP#1>
  where E is a type-variable:
    E extends Enum<E> declared in method <E>allOf(Class<E>)
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Enum from capture of ? extends Enum
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/internal/Lists.java:37: warning: [unchecked] Possible heap pollution from parameterized vararg type K
    public static <K> List<K> newArrayList(K... c) {
                                                ^
  where K is a type-variable:
    K extends Object declared in method <K>newArrayList(K...)
external/JCommander/jcommander-05254453c0a824f719bd72dac66fa686525752a5/src/main/java/com/beust/jcommander/internal/Maps.java:35: warning: [unchecked] Possible heap pollution from parameterized vararg type T
  public static <T> Map<T, T> newHashMap(T... parameters) {
                                              ^
  where T is a type-variable:
    T extends Object declared in method <T>newHashMap(T...)

I'm using --java_runtime_version=remotejdk_11 in Bazel as suggested in https://bazel.build/docs/bazel-and-java#hermetic-testing. I'm also using JCommander commit 0525445 (the archive for which is pulled in Copybara commit 19ed647).

@mkarg
Copy link
Collaborator

mkarg commented Apr 10, 2024

Feel free to file a PR if you like to get rid of the warnings. :-)

@jtilahun
Copy link
Author

jtilahun commented Apr 25, 2024

Looking around the codebase, I'm noticing that the SuppressWarnings annotation is used in a few places in the codebase. In particular, @SuppressWarnings("unchecked") appears in a few places. Are there any particular reasons for suppressing warnings as opposed to resolving the concerns that the warnings hint at? It's not clear whether the preference would be to suppress warnings or to try to actually resolve them. Frankly, it's not even clear whether the warnings are just noise or they're indicative of actual problems (which is itself worrisome).

@mkarg
Copy link
Collaborator

mkarg commented Apr 25, 2024

If you feel uncomfortable with suppressed warnings, feel free to provide a PR that resolves the underlying problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants