Skip to content

Commit 6fcc3ab

Browse files
committed
fixed UnsupportedOperationException: PermittedSubclasses requires ASM9 (#156)
1 parent 04f694a commit 6fcc3ab

File tree

7 files changed

+58
-21
lines changed

7 files changed

+58
-21
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Fixed
1010
- Process files in the order they appear in the respective input archives or directories.
1111
This fixes a regression that was introduced with directory support in version 3.0.0.
12+
- Fixed `UnsupportedOperationException` that occurred for Java 17 class files when excluding classes from obfuscation
13+
using the `extends` or `implements` attributes of the `rename.keep.class` element in the yGuard ANT task.
1214

1315
## [4.1.0]
1416

@@ -117,7 +119,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
117119

118120
## [2.7.2] - 2019-09-26
119121
### Fixed
120-
- Fixed `UnsupportedOperationException` that occurred for Java 11 class files when excluding classes from obfuscation using the `extends` or `implements` attributes of the `rename.keep.class` element in the yGuard ANT task.
122+
- Fixed `UnsupportedOperationException` that occurred for Java 11 class files when excluding classes from obfuscation using the `extends` or `implements` attributes of the `rename.keep.class` element in the yGuard ANT task.
121123
- Fixed yGuard's `language-conformity` mode `illegal` to no longer produce unqualified names that contain dots or spaces.
122124

123125
## [2.7.1] - 2019-02-26

src/main/java/com/yworks/yshrink/core/OutputVisitor.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @author Michael Schroeder, yWorks GmbH http://www.yworks.com
1414
*/
1515
public class OutputVisitor extends ClassVisitor {
16+
static final int OPCODES_ASM = Opcodes.ASM9;
1617

1718
private ClassVisitor cv;
1819
private Model model;
@@ -33,7 +34,7 @@ public class OutputVisitor extends ClassVisitor {
3334
* @param createStubs the create stubs
3435
*/
3536
public OutputVisitor( final ClassVisitor cv, final Model model, boolean createStubs ) {
36-
super(Opcodes.ASM7);
37+
super(OPCODES_ASM);
3738
this.createStubs = createStubs;
3839
this.cv = cv;
3940
this.model = model;
@@ -215,7 +216,7 @@ class OutputMethodVisitor extends MethodVisitor {
215216
* @param delegate the delegate
216217
*/
217218
public OutputMethodVisitor( MethodVisitor delegate ) {
218-
super(Opcodes.ASM7);
219+
super(OPCODES_ASM);
219220
this.delegate = delegate;
220221
}
221222

@@ -429,7 +430,7 @@ class OutputFieldVisitor extends FieldVisitor {
429430
* @param delegate the delegate
430431
*/
431432
public OutputFieldVisitor(FieldVisitor delegate) {
432-
super(Opcodes.ASM7);
433+
super(OPCODES_ASM);
433434
this.delegate = delegate;
434435
}
435436

@@ -487,7 +488,7 @@ class StubOutputMethodVisitor extends MethodVisitor {
487488
* @param visitStub the visit stub
488489
*/
489490
public StubOutputMethodVisitor(MethodVisitor delegate, boolean visitStub) {
490-
super(Opcodes.ASM7);
491+
super(OPCODES_ASM);
491492
this.delegate = delegate;
492493
this.visitStub = visitStub;
493494
}
@@ -608,7 +609,7 @@ static class DoNothingAnnotationVisitor extends AnnotationVisitor {
608609
* Instantiates a new Do nothing annotation visitor.
609610
*/
610611
public DoNothingAnnotationVisitor() {
611-
super(Opcodes.ASM7);
612+
super(OPCODES_ASM);
612613
}
613614

614615
public void visit( String name, Object value ) {
@@ -647,7 +648,7 @@ class OutputAnnotationVisitor extends AnnotationVisitor {
647648
* @param delegate the delegate
648649
*/
649650
public OutputAnnotationVisitor( AnnotationVisitor delegate ) {
650-
super(Opcodes.ASM7);
651+
super(OPCODES_ASM);
651652
this.delegate = delegate;
652653
}
653654

src/main/java/com/yworks/yshrink/model/ModelVisitor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ModelVisitor extends ClassVisitor {
2121
/**
2222
* The Opcodes asm.
2323
*/
24-
static final int OPCODES_ASM = Opcodes.ASM7;
24+
static final int OPCODES_ASM = Opcodes.ASM9;
2525

2626
private Model model;
2727

src/test/java/com/yworks/yguard/obf/KeepExtendsTest.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,9 @@
3030
* @author Thomas Behr
3131
*/
3232
public class KeepExtendsTest extends AbstractObfuscationTest {
33-
/**
34-
* The Name.
35-
*/
3633
@Rule
3734
public TestName name = new TestName();
3835

39-
/**
40-
* Test extends.
41-
*
42-
* @throws Exception the exception
43-
*/
4436
@Test
4537
public void testExtends() throws Exception {
4638
impl(new TypeStruct("asm/AbstractBaseClass.txt", "com.yworks.ext.test.AbstractBaseClass"),
@@ -49,16 +41,23 @@ public void testExtends() throws Exception {
4941
new TypeStruct("asm/Sample.txt", "com.yworks.impl.test.Sample"));
5042
}
5143

52-
/**
53-
* Test nests.
54-
*
55-
* @throws Exception the exception
56-
*/
5744
@Test
5845
public void testNests() throws Exception {
5946
impl(new TypeStruct("asm/OuterClass.txt", "com.yworks.yguard.obf.asm.OuterClass"));
6047
}
6148

49+
@Test
50+
public void testPermittedSubclasses() throws Exception {
51+
// PermittedSubclasses attribute is used only in Java 17 and newer
52+
if (17 <= getMajorVersion()) {
53+
impl(new TypeStruct("asm/SealedClassImpl.txt", "com.yworks.yguard.obf.asm.SealedClassImpl"),
54+
new TypeStruct("asm/SealedSerializableClass.txt", "com.yworks.yguard.obf.asm.SealedSerializableClass"),
55+
new TypeStruct("asm/SimpleClass.txt", "com.yworks.yguard.obf.asm.SimpleClass"));
56+
} else {
57+
System.err.println("Run test with Java 17 or newer.");
58+
}
59+
}
60+
6261
private void impl( final TypeStruct... types ) throws Exception {
6362
assertTrue("Invalid Java version", 11 <= getMajorVersion());
6463

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.yworks.yguard.obf.asm;
2+
3+
public final class SealedClassImpl extends SealedSerializableClass {
4+
public SealedClassImpl() {
5+
super(666);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.yworks.yguard.obf.asm;
2+
3+
import java.io.Serializable;
4+
5+
public sealed class SealedSerializableClass implements Serializable permits SealedClassImpl {
6+
private int data;
7+
8+
public SealedSerializableClass( final int data ) {
9+
this.data = data;
10+
}
11+
12+
public int getData() {
13+
return data;
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.yworks.yguard.obf.asm;
2+
3+
public class SimpleClass {
4+
private int data;
5+
6+
public SimpleClass( final int data ) {
7+
this.data = data;
8+
}
9+
10+
public int getData() {
11+
return data;
12+
}
13+
}

0 commit comments

Comments
 (0)