title: Explanation for "Cannot access 'x' in 'y' in multi catch clause when build with Maven
body: <p>I'm puzzled of the following compiler error &quot;java.lang.Throwable.getMessage() is defined in an inaccessible class or interface&quot; when I catch multiple exceptions, which inherit from same package protected abstract class.</p>
  <p>The Maven build fails (Maven 3.8.x on Win/Mac/Unix ), compiling it with javac works.</p>
  <p>But if I:</p>
  <ul>
  <li>only catch a single exception -&gt; compiles</li>
  <li>catch  multiple exceptions (which inherit from same package protected abstract class) and add another exception (i.e. RuntimeException) -&gt; compiles</li>
  </ul>
  <p>Can anyone explain this behavior to me?</p>
  <p>Main.java:</p>
  <pre><code>package com.foo.service;
  
  import com.foo.utils.ExceptionA;
  import com.foo.utils.ExceptionB;
  
  public class Main {
  
    public static void main(String[] args) {
  
      try {
        if (true) {
          throw new RuntimeException(&quot;RuntimeException&quot;);
        }
        if(true) {
          throw new ExceptionA(&quot;ExceptionA&quot;);
        }
        if (true) {
          throw new ExceptionB(&quot;ExceptionA&quot;);
        }
      } 
       catch (ExceptionA | ExceptionB e) { // &lt;- won't compile: &quot;Cannot access 'getMessage()' in 'java.lang.Throwable'&quot;
       e.getMessage();
      }
     //  catch (ExceptionA e) {  // &lt;- compiles
     //  e.getMessage();
     // }
     //  catch (ExceptionA | ExceptionB | RuntimeException e) { // &lt;- compiles
      // e.getMessage();
      // }
    }
  }
  </code></pre>
  <p>AbstractException.java:</p>
  <pre><code>package com.foo.utils;
  
  class AbstractException extends Exception {
    protected AbstractException(final String message){
      super(message);
    }
  }
  </code></pre>
  <p>ExceptionA.java:</p>
  <pre><code>package com.foo.utils;
  
  public class ExceptionA extends AbstractException {
    public ExceptionA(String message) {
      super(message);
    }
  }
  </code></pre>
  <p>ExceptionB.java:</p>
  <pre><code>package com.foo.utils;
  
  public class ExceptionB extends AbstractException {
    public ExceptionB(String message) {
      super(message);
    }
  }
  </code></pre>
  <p>pom.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
           xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
           xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;org.example&lt;/groupId&gt;
      &lt;artifactId&gt;foo&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
      &lt;properties&gt;
          &lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  
  &lt;/project&gt;
  </code></pre>