Bug 22959 - Cannot find symbol exception when inheriting from Java.Lang.RuntimeException
Summary: Cannot find symbol exception when inheriting from Java.Lang.RuntimeException
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.16.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: 5.1
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-09-12 16:55 UTC by John Miller [MSFT]
Modified: 2015-03-12 17:51 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Case (10.82 KB, application/zip)
2014-09-12 16:55 UTC, John Miller [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description John Miller [MSFT] 2014-09-12 16:55:32 UTC
Created attachment 8051 [details]
Test Case

**Overview:**

   Inheriting from Java.Lang.RuntimeException causes an exception when compiling. 

**Steps to Reproduce:**

   1. Compile the attached project in VS.

**Actual Results:**

>Error 1 cannot find symbol
>symbol : constructor RuntimeException(java.lang.String,java.lang.Throwable,boolean,boolean)
>location: class java.lang.RuntimeException
>super (p0, p1, p2, p3);

**Expected Results:**

   No exception.

**Build Date & Platform:**

   XVS 5.5.57

**Additional Information:**

   This code seemed to work in a (unknown) previous version.
Comment 1 Sadik Ali 2014-09-15 06:14:03 UTC
I have checked this issue and I am able to reproduce this issue.

I observed that when I build the attached test cases, I am getting following build error.

" no suitable constructor found for RuntimeException(String,Throwable,boolean,boolean)
		super (p0, p1, p2, p3);"
    
Screencast: http://www.screencast.com/t/K4iw8Bid5A

Error Details: https://gist.github.com/saurabh360/c9fbf7e97f5769e38194
Build Output: https://gist.github.com/saurabh360/57077d0dfffb218627ea

Environment Info: 

=== Xamarin Studio ===

Version 5.5 (build 185)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
Runtime:
	Mono 3.8.0 ((no/45d0ba1)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000009

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: 8.0.0.36 (Enterprise Edition)
Hash: 921d22f
Branch: 
Build date: 2014-09-12 21:10:42-0400

=== Xamarin.Android ===

Version: 4.16.0 (Enterprise Edition)
Android SDK: /Users/jatin66/Desktop/Backup/android-sdk-macosx
	Supported Android versions:
		1.6   (API level 4)
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.0   (API level 11)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: 1.12.0.1 (Enterprise Edition)

=== Build Information ===

Release ID: 505000185
Git revision: 31ed07d70102b543b3658da1bdfc1936798e8a89
Build date: 2014-09-12 19:16:13-04
Xamarin addins: 219ade5bee1af21074662c240e94c52dec972619

=== Operating System ===

Mac OS X 10.9.3
Darwin Jatin66s-iMac.local 13.2.0 Darwin Kernel Version 13.2.0
    Thu Apr 17 23:03:13 PDT 2014
    root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64
Comment 2 Bart 2014-09-17 12:07:14 UTC
Hi Jon, do you happen to have any idea on a timeline as to when this will get fixed?

Thanks
Comment 3 Bart 2014-09-18 15:36:00 UTC
I just noticed that according to the docs(http://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html), this overload of the  Java.Lang.RuntimeException constructer that is related to the error is marked as protected whereas the all the other constructors are marked as public. Is this possibly why the compiler is saying that it can't find the symbol?
Comment 4 Jonathan Pryor 2014-10-03 16:49:51 UTC
This is a very weird error.

> $ javac \
> -classpath /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v4.4/mono.android.jar \
> -bootclasspath /opt/android/sdk-tool/sdk/platforms/android-L/android.jar \
> obj/Debug/android/src/testruntimeexception/Example_ExampleException.java

`javac -bootclasspath` controls which java.lang types are used, so on my machine I'm using android-L/android.jar.

Let's look at java.lang.RuntimeException:

> $ javap \
> -classpath /opt/android/sdk-tool/sdk/platforms/android-L/android.jar \
> java.lang.RuntimeException

> Compiled from "RuntimeException.java"
> public class java.lang.RuntimeException extends java.lang.Exception {
>   static final long serialVersionUID;
>   public java.lang.RuntimeException();
>   public java.lang.RuntimeException(java.lang.String);
>   public java.lang.RuntimeException(java.lang.String, java.lang.Throwable);
>   public java.lang.RuntimeException(java.lang.Throwable);
>   protected java.lang.RuntimeException(java.lang.String, java.lang.Throwable, boolean, boolean);
> }

Clearly it does have a RuntimeException(String, Throwable, boolean, boolean) constructor!

Yet trying to use it fails:

> constructor RuntimeException.RuntimeException(Throwable) is not applicable
>   (actual and formal argument lists differ in length)
> constructor RuntimeException.RuntimeException(String,Throwable) is not applicable
>   (actual and formal argument lists differ in length)
> constructor RuntimeException.RuntimeException(String) is not applicable
>   (actual and formal argument lists differ in length)
> constructor RuntimeException.RuntimeException() is not applicable
>   (actual and formal argument lists differ in length)

Note that when javac runs, it mentions which constructors it's attempting to use. Further note that it does't ever look at the RuntimeException(String, Throwable, boolean, boolean) constructor!

> Is [the constructor being `protected`] possibly why the compiler
> is saying that it can't find the symbol?

That shouldn't be the case; the point to `protected` is that subclasses can use it, and we're clearly a subclass here.

The final Pièce de résistance?  This compiles with normal desktop Java:

  class DRE extends RuntimeException {
    public DRE (String p0, Throwable p1, boolean p2, boolean p3)
    {
      super (p0, p1, p2, p3);
    }
  }

It fails to compile with API-L.
Comment 5 Jonathan Pryor 2014-10-03 17:03:07 UTC
A related "very funny thing": Despite `javap` stating that there is a RuntimeException(String, Throwable, boolean, boolean) constructor, Android git doesn't show one:

https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/lang/RuntimeException.java

I think the *real* problem is that javap can't properly show the members of types that are loaded from the JVM. The .NET analogue is trying to load types from mscorlib.dll 2.0 when running within a .NET 1.0 process; There Can Be Only One™ mscorlib.dll loaded within a process, so while this *looks* like it works, what actually happens is loading mscorlib.dll 2.0 results in silently getting mscorlib.dll 1.0.

The JVM is the same but different here, and thus `javap` output is unreliable (it LIES!), showing the RuntimeException members that come from the "host" JVM, not the target android.jar file.

Which explains most of my confusion...
Comment 6 Jonathan Pryor 2014-10-03 17:21:42 UTC
Fixed in monodroid/d6119447.

WORKAROUND: Don't inherit from RuntimeException (or Exception!).

Inheriting from Java.Lang.Throwable will work.
Comment 7 Bart 2014-10-03 17:23:01 UTC
Good to know. Thanks for looking into this Jon.
Comment 8 Danish Akhtar 2015-02-06 06:15:00 UTC
We are still getting this issue with both XS ans VS, I am getting >Error 1 cannot find symbol: constructorRuntimeException(java.lang.String,java.lang.Throwable,boolean,boolean)
location: class java.lang.RuntimeException
super (p0, p1, p2, p3);

while running attached sample in ide.

Hence reopening this issue.

Supplement info:
build output: https://gist.github.com/Mohit-Kheterpal/04c4c23155c21a79df15
error details: https://gist.github.com/Mohit-Kheterpal/09cd4b1629e6029b8b00
ide logs: https://gist.github.com/Mohit-Kheterpal/45668cc76ee1a260b459

Environment info:
=== Xamarin Studio ===

Version 5.7.1 (build 17)
Installation UUID: 3dbf10c4-ed30-4e55-8a8b-1704777c7b5f
Runtime:
 Mono 3.12.0 ((detached/de2f33f)
 GTK+ 2.24.23 (Raleigh theme)

 Package version: 312000076

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: 8.6.1.20 (Trial Edition)
Hash: 3b3ef43
Branch: 
Build date: 2015-01-24 09:42:21-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Trial Edition)
Android SDK: /Users/apprpject/Desktop/android-sdk-macosx
 Supported Android versions:
  2.1    (API level 7)
  2.2    (API level 8)
  2.3    (API level 10)
  3.1    (API level 12)
  4.0    (API level 14)
  4.0.3  (API level 15)
  4.1    (API level 16)
  4.2    (API level 17)
  4.3    (API level 18)
  4.4    (API level 19)
  4.4.87 (API level 20)
  5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: 1.12.0.4 (Starter Edition)

=== Build Information ===

Release ID: 507010017
Git revision: 0bc7d3550b6b088ac25b08dcf7bbe73bcc8658b3
Build date: 2015-02-03 19:43:29-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

=== Operating System ===

Mac OS X 10.8.5
Darwin localhost 12.5.0 Darwin Kernel Version 12.5.0
    Sun Sep 29 13:33:47 PDT 2013
    root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64
Comment 9 Jonathan Pryor 2015-02-06 08:19:58 UTC
This was not fixed in 4.20. This was fixed in 5.0. Please try testing master.
Comment 10 Danish Akhtar 2015-02-10 04:06:03 UTC
We are not getting this issue with XA 5.0, attached sample is running successfully in both XS and VS. Hence closing this issue.

Environment info:=== Xamarin Studio ===

Version 5.7.1 (build 17)
Installation UUID: 3dbf10c4-ed30-4e55-8a8b-1704777c7b5f
Runtime:
	Mono 3.12.0 ((detached/de2f33f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000076

=== Xamarin.Android ===

Version: 5.0.0.18 (Trial Edition)
Android SDK: /Users/apprpject/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: 8.9.1.44 (Trial Edition)
Hash: 5482a19
Branch: master
Build date: 2015-01-31 13:50:55-0500

=== Xamarin.Mac ===

Version: 1.12.0.4 (Trial Edition)

=== Build Information ===

Release ID: 507010017
Git revision: 0bc7d3550b6b088ac25b08dcf7bbe73bcc8658b3
Build date: 2015-02-03 19:43:29-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

=== Operating System ===

Mac OS X 10.8.5
Darwin localhost 12.5.0 Darwin Kernel Version 12.5.0
    Sun Sep 29 13:33:47 PDT 2013
    root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64