forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not transform invokespecial instructions produced for direct insta…
…ntiations. The instruction invokespecial is also used to invoke constructors and perform object instantiation. This CL fixes Hilt's transform to not change the owner of such instructions even if the owner is the older superclass since they are instantiating an object that happens to be the of the same type as the 'old' superclass. Fixes #2662 RELNOTES=Fix an issue in Hilt's bytecode transform that would cause classes to fail validation if they contained an instantiation of an object whose type is the same as the superclass of the @androidentrypoint annotated class. PiperOrigin-RevId: 378500741
- Loading branch information
1 parent
38077ee
commit 839a849
Showing
4 changed files
with
122 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...simple/app/src/sharedTest/java/dagger/hilt/android/simple/InvokeSpecialTransformTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (C) 2020 The Dagger Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dagger.hilt.android.simple; | ||
|
||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.widget.FrameLayout; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.lifecycle.Lifecycle.State; | ||
import androidx.test.core.app.ActivityScenario; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import dagger.hilt.android.AndroidEntryPoint; | ||
import dagger.hilt.android.testing.HiltAndroidRule; | ||
import dagger.hilt.android.testing.HiltAndroidTest; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** Test that verifies edge cases of invokespecial instructions transformation. */ | ||
@HiltAndroidTest | ||
@RunWith(AndroidJUnit4.class) | ||
public class InvokeSpecialTransformTest { | ||
|
||
@Rule | ||
public HiltAndroidRule rule = new HiltAndroidRule(this); | ||
|
||
@Test | ||
public void constructorCallOfOldSuperclass() { | ||
try (ActivityScenario<TestActivity> scenario = ActivityScenario.launch(TestActivity.class)) { | ||
scenario.moveToState(State.DESTROYED); | ||
} | ||
} | ||
|
||
/** A test activity */ | ||
@AndroidEntryPoint | ||
public static final class TestActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(new CustomView(this).createBrother()); | ||
} | ||
} | ||
|
||
/** A custom view for testing */ | ||
@AndroidEntryPoint | ||
public static class CustomView extends FrameLayout { | ||
|
||
public CustomView(@NonNull Context context) { | ||
// This super call is an invokespecial that should be transformed | ||
super(context); | ||
// This invokespecial that should not be transformed. | ||
FrameLayout secondInvokeSpecial = new FrameLayout(getContext()); | ||
} | ||
|
||
FrameLayout createBrother() { | ||
// This invokespecial that should not be transformed. | ||
return new FrameLayout(getContext()); | ||
} | ||
} | ||
} |