|
1 | | -// No need for Java code since only testing XML files |
2 | | -public class Test { } |
| 1 | +package com.example.myapp; |
| 2 | + |
| 3 | +import android.app.Fragment; |
| 4 | +import android.os.Bundle; |
| 5 | +import android.view.LayoutInflater; |
| 6 | +import android.view.View; |
| 7 | +import android.view.ViewGroup; |
| 8 | +import android.widget.Button; |
| 9 | +import androidx.fragment.app.FragmentActivity; |
| 10 | +import androidx.fragment.app.FragmentTransaction; |
| 11 | + |
| 12 | +public class Test extends FragmentActivity { |
| 13 | + |
| 14 | + @Override |
| 15 | + public void onCreate(Bundle savedInstance) { |
| 16 | + try { |
| 17 | + super.onCreate(savedInstance); |
| 18 | + final String fname = getIntent().getStringExtra("fname"); |
| 19 | + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); |
| 20 | + Class<Fragment> fClass = (Class<Fragment>) Class.forName(fname); |
| 21 | + ft.add(fClass.newInstance(), ""); // hasTaintFlow |
| 22 | + ft.add(0, Fragment.instantiate(this, fname), null); // hasTaintFlow |
| 23 | + ft.add(0, Fragment.instantiate(this, fname, null)); // hasTaintFlow |
| 24 | + ft.add(0, fClass, null, ""); // hasTaintFlow |
| 25 | + ft.add(0, fClass.newInstance(), ""); // hasTaintFlow |
| 26 | + ft.attach(fClass.newInstance()); // hasTaintFlow |
| 27 | + ft.replace(0, fClass, null); // hasTaintFlow |
| 28 | + ft.replace(0, fClass.newInstance()); // hasTaintFlow |
| 29 | + ft.replace(0, fClass, null, ""); // hasTaintFlow |
| 30 | + ft.replace(0, fClass.newInstance(), ""); // hasTaintFlow |
| 31 | + |
| 32 | + ft.add(Fragment.class.newInstance(), ""); // Safe |
| 33 | + ft.attach(Fragment.class.newInstance()); // Safe |
| 34 | + ft.replace(0, Fragment.class.newInstance(), ""); // Safe |
| 35 | + } catch (Exception e) { |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | +} |
0 commit comments