Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-3791

Unclear use of Java hint: “Illegal Use of instanceOf operator”

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • java - Hints
    • JDK 8 project, NetBeans running on JDK 13

    Description

      In an annotation processor similar to

      @SupportedAnnotationTypes("org.example.MyAnnotation")
      public final class MyGenerator 
              extends javax.annotation.processing.AbstractProcessor {
          @Override
          public boolean process(
                  final Set<? extends TypeElement> annotations,
                  final RoundEnvironment roundEnvironment) {
              final Set<? extends Element> elements
                      = roundEnvironment.getElementsAnnotatedWith(MyAnnotation.class);
              for (final Element element : elements) {
                  PackageElement packageElement = null;
                  for (Element currentElement = typeElement;
                          currentElement != null;
                          currentElement = currentElement.getEnclosingElement()) {
                      if (currentElement instanceof PackageElement) { // Illegal Use of instanceOf
                          packageElement = (PackageElement) currentElement;
                          break;
                      }
      

      I get the warning “Illegal Use of instanceOf operator” (in the line with the comment). It is unclear why this use would be illegal, as it works fine.

      The description of the hint in the options should clearly say why it’s illegal to use instanceOf or, if this warning is obsolete, the hint should be removed.

      (According to http://wiki.netbeans.org/Java_Hints, this hint is disabled by default.)

      Attachments

        Activity

          People

            jlahoda Jan Lahoda
            striderapache dennis lucero
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: