Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
dd13edf2
Commit
dd13edf2
authored
Mar 02, 2019
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: don't remove empty default constructor if other constructors exists (#460)
parent
653bb2ac
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
4 deletions
+83
-4
ClassModifier.java
...e/src/main/java/jadx/core/dex/visitors/ClassModifier.java
+23
-4
TestDefConstructorNotRemoved.java
...ests/integration/others/TestDefConstructorNotRemoved.java
+60
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java
View file @
dd13edf2
...
...
@@ -295,15 +295,34 @@ public class ClassModifier extends AbstractVisitor {
private
static
void
removeEmptyMethods
(
MethodNode
mth
)
{
AccessInfo
af
=
mth
.
getAccessFlags
();
// remove public empty constructors
// remove public empty constructors
(static or default)
if
(
af
.
isConstructor
()
&&
(
af
.
isPublic
()
||
af
.
isStatic
())
&&
mth
.
getArguments
(
false
).
isEmpty
()
&&
!
mth
.
contains
(
AType
.
JADX_ERROR
))
{
&&
mth
.
getArguments
(
false
).
isEmpty
())
{
List
<
BlockNode
>
bb
=
mth
.
getBasicBlocks
();
if
(
bb
==
null
||
bb
.
isEmpty
()
||
BlockUtils
.
isAllBlocksEmpty
(
bb
))
{
if
(
af
.
isStatic
()
&&
mth
.
getMethodInfo
().
isClassInit
())
{
mth
.
add
(
AFlag
.
DONT_GENERATE
);
}
else
{
// don't remove default constructor if other constructors exists
if
(
mth
.
isDefaultConstructor
()
&&
!
isNonDefaultConstructorExists
(
mth
))
{
mth
.
add
(
AFlag
.
DONT_GENERATE
);
}
}
}
}
}
private
static
boolean
isNonDefaultConstructorExists
(
MethodNode
defCtor
)
{
ClassNode
parentClass
=
defCtor
.
getParentClass
();
for
(
MethodNode
mth
:
parentClass
.
getMethods
())
{
if
(
mth
!=
defCtor
&&
mth
.
getAccessFlags
().
isConstructor
()
&&
mth
.
getMethodInfo
().
isConstructor
()
&&
!
mth
.
isDefaultConstructor
())
{
return
true
;
}
}
return
false
;
}
}
jadx-core/src/test/java/jadx/tests/integration/others/TestDefConstructorNotRemoved.java
0 → 100644
View file @
dd13edf2
package
jadx
.
tests
.
integration
.
others
;
import
org.junit.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestDefConstructorNotRemoved
extends
IntegrationTest
{
public
static
class
TestCls
{
static
{
// empty
}
public
static
class
A
{
private
final
String
s
;
public
A
()
{
s
=
"a"
;
}
public
A
(
String
str
)
{
s
=
str
;
}
}
public
static
class
B
extends
A
{
public
B
()
{
super
();
}
public
B
(
String
s
)
{
super
(
s
);
}
}
public
void
check
()
{
new
A
();
new
A
(
"a"
);
new
B
();
new
B
(
"b"
);
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
not
(
containsString
(
"super();"
)));
assertThat
(
code
,
not
(
containsString
(
"static {"
)));
assertThat
(
code
,
containsOne
(
"public B() {"
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment