Skip to content

Commit

Permalink
fixed UnsupportedOperationException: PermittedSubclasses requires ASM9 (
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasbehr committed Jul 16, 2024
1 parent 04f694a commit 6fcc3ab
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 21 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Process files in the order they appear in the respective input archives or directories.
This fixes a regression that was introduced with directory support in version 3.0.0.
- Fixed `UnsupportedOperationException` that occurred for Java 17 class files when excluding classes from obfuscation
using the `extends` or `implements` attributes of the `rename.keep.class` element in the yGuard ANT task.

## [4.1.0]

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

## [2.7.2] - 2019-09-26
### Fixed
- 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.
- 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.
- Fixed yGuard's `language-conformity` mode `illegal` to no longer produce unqualified names that contain dots or spaces.

## [2.7.1] - 2019-02-26
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/yworks/yshrink/core/OutputVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @author Michael Schroeder, yWorks GmbH http://www.yworks.com
*/
public class OutputVisitor extends ClassVisitor {
static final int OPCODES_ASM = Opcodes.ASM9;

private ClassVisitor cv;
private Model model;
Expand All @@ -33,7 +34,7 @@ public class OutputVisitor extends ClassVisitor {
* @param createStubs the create stubs
*/
public OutputVisitor( final ClassVisitor cv, final Model model, boolean createStubs ) {
super(Opcodes.ASM7);
super(OPCODES_ASM);
this.createStubs = createStubs;
this.cv = cv;
this.model = model;
Expand Down Expand Up @@ -215,7 +216,7 @@ class OutputMethodVisitor extends MethodVisitor {
* @param delegate the delegate
*/
public OutputMethodVisitor( MethodVisitor delegate ) {
super(Opcodes.ASM7);
super(OPCODES_ASM);
this.delegate = delegate;
}

Expand Down Expand Up @@ -429,7 +430,7 @@ class OutputFieldVisitor extends FieldVisitor {
* @param delegate the delegate
*/
public OutputFieldVisitor(FieldVisitor delegate) {
super(Opcodes.ASM7);
super(OPCODES_ASM);
this.delegate = delegate;
}

Expand Down Expand Up @@ -487,7 +488,7 @@ class StubOutputMethodVisitor extends MethodVisitor {
* @param visitStub the visit stub
*/
public StubOutputMethodVisitor(MethodVisitor delegate, boolean visitStub) {
super(Opcodes.ASM7);
super(OPCODES_ASM);
this.delegate = delegate;
this.visitStub = visitStub;
}
Expand Down Expand Up @@ -608,7 +609,7 @@ static class DoNothingAnnotationVisitor extends AnnotationVisitor {
* Instantiates a new Do nothing annotation visitor.
*/
public DoNothingAnnotationVisitor() {
super(Opcodes.ASM7);
super(OPCODES_ASM);
}

public void visit( String name, Object value ) {
Expand Down Expand Up @@ -647,7 +648,7 @@ class OutputAnnotationVisitor extends AnnotationVisitor {
* @param delegate the delegate
*/
public OutputAnnotationVisitor( AnnotationVisitor delegate ) {
super(Opcodes.ASM7);
super(OPCODES_ASM);
this.delegate = delegate;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/yworks/yshrink/model/ModelVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ModelVisitor extends ClassVisitor {
/**
* The Opcodes asm.
*/
static final int OPCODES_ASM = Opcodes.ASM7;
static final int OPCODES_ASM = Opcodes.ASM9;

private Model model;

Expand Down
25 changes: 12 additions & 13 deletions src/test/java/com/yworks/yguard/obf/KeepExtendsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,9 @@
* @author Thomas Behr
*/
public class KeepExtendsTest extends AbstractObfuscationTest {
/**
* The Name.
*/
@Rule
public TestName name = new TestName();

/**
* Test extends.
*
* @throws Exception the exception
*/
@Test
public void testExtends() throws Exception {
impl(new TypeStruct("asm/AbstractBaseClass.txt", "com.yworks.ext.test.AbstractBaseClass"),
Expand All @@ -49,16 +41,23 @@ public void testExtends() throws Exception {
new TypeStruct("asm/Sample.txt", "com.yworks.impl.test.Sample"));
}

/**
* Test nests.
*
* @throws Exception the exception
*/
@Test
public void testNests() throws Exception {
impl(new TypeStruct("asm/OuterClass.txt", "com.yworks.yguard.obf.asm.OuterClass"));
}

@Test
public void testPermittedSubclasses() throws Exception {
// PermittedSubclasses attribute is used only in Java 17 and newer
if (17 <= getMajorVersion()) {
impl(new TypeStruct("asm/SealedClassImpl.txt", "com.yworks.yguard.obf.asm.SealedClassImpl"),
new TypeStruct("asm/SealedSerializableClass.txt", "com.yworks.yguard.obf.asm.SealedSerializableClass"),
new TypeStruct("asm/SimpleClass.txt", "com.yworks.yguard.obf.asm.SimpleClass"));
} else {
System.err.println("Run test with Java 17 or newer.");
}
}

private void impl( final TypeStruct... types ) throws Exception {
assertTrue("Invalid Java version", 11 <= getMajorVersion());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.yworks.yguard.obf.asm;

public final class SealedClassImpl extends SealedSerializableClass {
public SealedClassImpl() {
super(666);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.yworks.yguard.obf.asm;

import java.io.Serializable;

public sealed class SealedSerializableClass implements Serializable permits SealedClassImpl {
private int data;

public SealedSerializableClass( final int data ) {
this.data = data;
}

public int getData() {
return data;
}
}
13 changes: 13 additions & 0 deletions src/test/resources/com/yworks/yguard/obf/asm/SimpleClass.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.yworks.yguard.obf.asm;

public class SimpleClass {
private int data;

public SimpleClass( final int data ) {
this.data = data;
}

public int getData() {
return data;
}
}

0 comments on commit 6fcc3ab

Please sign in to comment.