(#) Method considered overridden by Dalvik !!! ERROR: Method considered overridden by Dalvik This is an error. Id : `DalvikOverride` Summary : Method considered overridden by Dalvik Note : **This issue is disabled by default**; use `--enable DalvikOverride` Severity : Error Category : Correctness Platform : Android Vendor : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 Since : Initial Affects : Class files Editing : This check can *not* run live in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/OverrideDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/OverrideDetectorTest.kt) Copyright Year : 2012 The Dalvik virtual machine will treat a package private method in one class as overriding a package private method in its super class, even if they are in separate packages. If you really did intend for this method to override the other, make the method `protected` instead. If you did **not** intend the override, consider making the method private, or changing its name or signature. Note that this check is disabled be default, because ART (the successor to Dalvik) no longer has this behavior. (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/pkg2/Class2.java:7:Error: This package private method may be unintentionally overriding method in pkg1.Class1 [DalvikOverride] void method() { // Flag this as an accidental override ------ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here are the relevant source files: `src/pkg1/Class1.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers package pkg1; public class Class1 { void method() { } void method2(int foo) { } void method3() { } void method4() { } void method5() { } void method6() { } void method7() { } public static class Class4 extends Class1 { void method() { // Not an error: same package } } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `src/pkg2/Class2.java`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~java linenumbers package pkg2; import android.annotation.SuppressLint; import pkg1.Class1; public class Class2 extends Class1 { void method() { // Flag this as an accidental override } void method2(String foo) { // not an override: different signature } static void method4() { // not an override: static } private void method3() { // not an override: private } protected void method5() { // not an override: protected } public void method6() { // not an override: public } @SuppressLint("DalvikOverride") public void method7() { // suppressed: no warning } public class Class3 extends Object { void method() { // Not an override: not a subclass } } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/OverrideDetectorTest.kt) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test found for this lint check, `OverrideDetector.test`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. (##) Suppressing You can suppress false positives using one of the following mechanisms: * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: ```xml <?xml version="1.0" encoding="UTF-8"?> <lint> <issue id="DalvikOverride" severity="ignore" /> </lint> ``` Instead of `ignore` you can also change the severity here, for example from `error` to `warning`. You can find additional documentation on how to filter issues by path, regular expression and so on [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). * In Gradle projects, using the DSL syntax to configure lint. For example, you can use something like ```gradle lintOptions { disable 'DalvikOverride' } ``` In Android projects this should be nested inside an `android { }` block. * For manual invocations of `lint`, using the `--ignore` flag: ``` $ lint --ignore DalvikOverride ...` ``` * Last, but not least, using baselines, as discussed [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).