Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Jamie Mansfield
asm
Commits
2a673125
Commit
2a673125
authored
Jun 16, 2018
by
Eric Bruneton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add failing test showing the issue.
parent
15b1be2e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
asm/src/test/java/org/objectweb/asm/ClassVisitorTest.java
asm/src/test/java/org/objectweb/asm/ClassVisitorTest.java
+59
-0
No files found.
asm/src/test/java/org/objectweb/asm/ClassVisitorTest.java
View file @
2a673125
...
...
@@ -29,6 +29,10 @@ package org.objectweb.asm;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.provider.CsvSource
;
...
...
@@ -157,6 +161,34 @@ public class ClassVisitorTest extends AsmTest {
assertThatClass
(
copyPoolClassWriter
.
toByteArray
()).
isEqualTo
(
classWriter
.
toByteArray
());
}
/**
* Tests that a ClassReader -> class adapter -> ClassWriter chain give the same result when the
* descriptor of a method is changed.
*/
@Test
public
void
testReadAndWriteWithCopyPoolAndChangeDescriptor
()
{
ClassWriter
sourceClassWriter
=
new
ClassWriter
(
ClassWriter
.
COMPUTE_MAXS
);
sourceClassWriter
.
visit
(
Opcodes
.
V1_7
,
Opcodes
.
ACC_ABSTRACT
,
"C"
,
null
,
"java/lang/Object"
,
null
);
MethodVisitor
methodVisitor
=
sourceClassWriter
.
visitMethod
(
Opcodes
.
ACC_PUBLIC
,
"<init>"
,
"()V"
,
null
,
null
);
methodVisitor
.
visitCode
();
methodVisitor
.
visitVarInsn
(
Opcodes
.
ALOAD
,
0
);
methodVisitor
.
visitMethodInsn
(
Opcodes
.
INVOKESPECIAL
,
"java/lang/Object"
,
"<init>"
,
"()V"
,
false
);
methodVisitor
.
visitInsn
(
Opcodes
.
RETURN
);
methodVisitor
.
visitMaxs
(
0
,
0
);
methodVisitor
.
visitEnd
();
sourceClassWriter
.
visitEnd
();
ClassReader
classReader
=
new
ClassReader
(
sourceClassWriter
.
toByteArray
());
ClassWriter
classWriter
=
new
ClassWriter
(
ClassWriter
.
COMPUTE_MAXS
);
ClassWriter
copyPoolClassWriter
=
new
ClassWriter
(
classReader
,
ClassWriter
.
COMPUTE_MAXS
);
classReader
.
accept
(
new
AddParameterAdapter
(
classWriter
),
0
);
classReader
.
accept
(
new
AddParameterAdapter
(
copyPoolClassWriter
),
0
);
assertThatClass
(
copyPoolClassWriter
.
toByteArray
()).
isEqualTo
(
classWriter
.
toByteArray
());
}
/** Test that classes with only visible or only invisible annotations can be read correctly. */
@ParameterizedTest
@ValueSource
(
strings
=
{
"true"
,
"false"
})
...
...
@@ -535,4 +567,31 @@ public class ClassVisitorTest extends AsmTest {
};
}
}
/** A class visitor which adds a parameter to the declared method descriptors. */
private
static
class
AddParameterAdapter
extends
ClassVisitor
{
public
AddParameterAdapter
(
final
ClassVisitor
classVisitor
)
{
super
(
Opcodes
.
ASM7_EXPERIMENTAL
,
classVisitor
);
}
@Override
public
MethodVisitor
visitMethod
(
final
int
access
,
final
String
name
,
final
String
descriptor
,
final
String
signature
,
final
String
[]
exceptions
)
{
List
<
Type
>
argumentTypes
=
new
ArrayList
<>(
Arrays
.
asList
(
Type
.
getArgumentTypes
(
descriptor
)));
argumentTypes
.
add
(
Type
.
INT_TYPE
);
Type
returnType
=
Type
.
getReturnType
(
descriptor
);
return
super
.
visitMethod
(
access
,
name
,
Type
.
getMethodDescriptor
(
returnType
,
argumentTypes
.
toArray
(
new
Type
[
argumentTypes
.
size
()])),
signature
,
exceptions
);
}
}
}
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