This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 269828 - False positive: "incompatible types"
Summary: False positive: "incompatible types"
Status: REOPENED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-14 22:32 UTC by bastik
Modified: 2017-06-19 16:28 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bastik 2017-02-14 22:32:53 UTC
The following code compiles without problems (Java 8) but Netbeans indicates an error for line 2:

1: final javax.swing.table.TableRowSorter<? extends javax.swing.table.TableModel> sorter = null;
2: sorter.setRowFilter(javax.swing.RowFilter.andFilter(null));

The error is "incompatible types: RowFilter<CAP#1,Integer> cannot be converted to RowFilter<? super CAP#1,? super Integer>"

Please ignore the fact that you would get NullPointerExceptions at runtime, the code is just to demonstrate the error and not supposed to be executed.
Comment 1 Svata Dedic 2017-03-09 13:54:42 UTC
Please note that NetBeans process files using its bundled javac, which may differ in minor details from the platform.

I cannot reproduce the defect in 8.2 release or dev trunk; it's possible that the defect was fixed in JDK/NB already.
Comment 2 russkiy 2017-06-19 16:15:58 UTC
Steps to reproduce:
1. Create new maven project for JDK 1.8
2. Create single class file:
----------------------------
package netbeans.bug;

import static org.hamcrest.MatcherAssert.assertThat;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;

public class Proof
{
   public static void main(final String[] args)
   {
      assertThat(new Value("hello bug"), Matchers.both(okWithMatcherOne()).and(okWithMatcherTwo()));
      System.out.println("Bug detected.");
   }

   private static Matcher<? super Value> okWithMatcherOne()
   {
      return new MatcherOne();
   }

   private static Matcher<? super Value> okWithMatcherTwo()
   {
      return new MatcherTwo();
   }

   public static class MatcherOne implements Matcher<Value>
   {
      @Override
      public boolean matches(final Object item)
      {
         return true;
      }

      @Override
      public void describeMismatch(final Object item, final Description mismatchDescription)
      {
         throw new UnsupportedOperationException("Not implemented yet.");
      }

      @Override
      public void _dont_implement_Matcher___instead_extend_BaseMatcher_()
      {
         throw new UnsupportedOperationException("Not implemented yet.");
      }

      @Override
      public void describeTo(final Description description)
      {
         throw new UnsupportedOperationException("Not implemented yet.");
      }
   }

   public static class MatcherTwo implements Matcher<Value>
   {
      @Override
      public boolean matches(final Object item)
      {
         return true;
      }

      @Override
      public void describeMismatch(final Object item, final Description mismatchDescription)
      {
         throw new UnsupportedOperationException("Not implemented yet.");
      }

      @Override
      public void _dont_implement_Matcher___instead_extend_BaseMatcher_()
      {
         throw new UnsupportedOperationException("Not implemented yet.");
      }

      @Override
      public void describeTo(final Description description)
      {
         throw new UnsupportedOperationException("Not implemented yet.");
      }
   }

   public static class Value
   {
      final String data;

      Value(final String data)
      {
         this.data = data;
      }
   }
}
-----------------------
3. Download all required libs from Maven repo.
4. Clean and Build the project.
5. Run the file.
Result:

[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building POCs 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.2.1:exec (default-cli) @ POCs ---
Bug detected.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.550s
[INFO] Finished at: Mon Jun 19 17:12:27 BST 2017
[INFO] Final Memory: 11M/619M
[INFO] ------------------------------------------------------------------------
Comment 3 russkiy 2017-06-19 16:19:38 UTC
Don't know how to attach screenshot, but in above class the string "okWithMatcherTwo()" is highlighted as error:

"incompatible types: Matcher<CAP#1> can not be converted to Matcher<? super CAP#2>"
Comment 4 russkiy 2017-06-19 16:28:07 UTC
Windows 7, JDK 1.8.0_131