Skip to content

api-compatibility needs to check [Register] attribute values. #1118

Closed
@jonpryor

Description

@jonpryor

Related: PR #930
Related: https://bugzilla.xamarin.com/show_bug.cgi?id=60069

We need an API compatibility check that not only ensure that we don't break API -- which tests/api-compatibility does -- but also that we don't break semantics. The problem with Bug #60069 was that the semantics of Build.Serial changed from a Java field read to a Java method invocation, and since the Build.getSerial() method that was invoked only existed in API-26, the result was that the formerly working expression Build.Serial now threw everywhere.

We need to check for and prevent this in the future.

My current idea is that we improve mono-api-html to check the values of custom attributes, and warn if they change. For example, with Build.Serial the [Register] attribute contents changed:

		// API < 26, field use:
		[Register ("SERIAL", ApiSince = 9)]
		public static string Serial {
			get {
				const string __id = "SERIAL.Ljava/lang/String;";

				var __v = _members.StaticFields.GetObjectValue (__id);
				return JNIEnv.GetString (__v.Handle, JniHandleOwnership.TransferLocalRef);
			}
		}

		// API >= 26, method invocation:
		[Register ("getSerial", "()Ljava/lang/String;", "", ApiSince = 26)]
		public static string Serial {
			get {
				const string __id = "getSerial.()Ljava/lang/String;";

				try {
					var __rm = _members.StaticMethods.InvokeObjectMethod (__id, null);
					return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef);
				} finally {
				}
			}
		}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions