Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

de-compile enum StackOverflowError #67

Open
zcoNick opened this issue May 24, 2022 · 0 comments
Open

de-compile enum StackOverflowError #67

zcoNick opened this issue May 24, 2022 · 0 comments

Comments

@zcoNick
Copy link

zcoNick commented May 24, 2022

Using ByteBuddy generate enum Gender, get byte array, de-compile to source. Throw StackOverflowError.

java.lang.StackOverflowError
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadClassFile(TypeMaker.java:1577)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadFieldsAndMethods(TypeMaker.java:1473)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadFieldsAndMethods(TypeMaker.java:1457)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1261)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1298)
	at org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.loadMethodTypes(TypeMaker.java:1269)
	...repeat...

My code is:

String enumClassName = "com.zco.lab.jdcore.enums.Gender";
DynamicType.Unloaded<? extends Enum<?>> unloaded = new ByteBuddy(ClassFileVersion.JAVA_V8)
        .makeEnumeration("MALE", "FEMALE")
        .name(enumClassName)
        .make();
// save class
unloaded.saveIn(new File("target/classes"));
byte[] bytes = unloaded.getBytes();
// de-compile
deCompile(enumClassName, bytes);

method deCompile:

private void deCompile(String className, byte[] bytes) throws Exception {
    Loader loader = new Loader() {
        @Override
        public boolean canLoad(String s) {
            return true;
        }

        @Override
        public byte[] load(String s) throws LoaderException {
            return bytes;
        }
    };
    Printer printer = new Printer() {
        protected static final String TAB = "  ";
        protected static final String NEWLINE = "\n";

        protected int indentationCount = 0;
        protected final StringBuilder sb = new StringBuilder();

        @Override
        public String toString() {
            return sb.toString();
        }

        @Override
        public void start(int maxLineNumber, int majorVersion, int minorVersion) {
        }

        @Override
        public void end() {
        }

        @Override
        public void printText(String text) {
            sb.append(text);
        }

        @Override
        public void printNumericConstant(String constant) {
            sb.append(constant);
        }

        @Override
        public void printStringConstant(String constant, String ownerInternalName) {
            sb.append(constant);
        }

        @Override
        public void printKeyword(String keyword) {
            sb.append(keyword);
        }

        @Override
        public void printDeclaration(int type, String internalTypeName, String name, String descriptor) {
            sb.append(name);
        }

        @Override
        public void printReference(int type, String internalTypeName, String name, String descriptor,
                                   String ownerInternalName) {
            sb.append(name);
        }

        @Override
        public void indent() {
            this.indentationCount++;
        }

        @Override
        public void unindent() {
            this.indentationCount--;
        }

        @Override
        public void startLine(int lineNumber) {
            for (int i = 0; i < indentationCount; i++) sb.append(TAB);
        }

        @Override
        public void endLine() {
            sb.append(NEWLINE);
        }

        @Override
        public void extraLine(int count) {
            while (count-- > 0) sb.append(NEWLINE);
        }

        @Override
        public void startMarker(int type) {
        }

        @Override
        public void endMarker(int type) {
        }
    };

    ClassFileToJavaSourceDecompiler decompiler = new ClassFileToJavaSourceDecompiler();

    String path = className.replace(".", "/");

    decompiler.decompile(loader, printer, path);

    String source = printer.toString();
    System.out.println(source);
    System.out.println();
}

Maven dependencies

<dependency>
    <groupId>net.bytebuddy</groupId>
    <artifactId>byte-buddy</artifactId>
    <version>1.12.10</version>
</dependency>
<dependency>
    <groupId>org.jd</groupId>
    <artifactId>jd-core</artifactId>
    <version>1.1.3</version>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.2</version>
</dependency>

Open Gender.class in Idea is OK.
Open Gender.class with JD-GUI 1.6.6 (jd-core 1.1.3) is OK.
image

yaojieno1 pushed a commit to yaojieno1/jd-core that referenced this issue Feb 20, 2024
* Bump jaxb-core from 4.0.1 to 4.0.2

Bumps jaxb-core from 4.0.1 to 4.0.2.

---
updated-dependencies:
- dependency-name: com.sun.xml.bind:jaxb-core
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump jaxb-impl from 4.0.1 to 4.0.2

Bumps jaxb-impl from 4.0.1 to 4.0.2.

---
updated-dependencies:
- dependency-name: com.sun.xml.bind:jaxb-impl
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump kafka-clients from 3.3.2 to 3.4.0

Bumps kafka-clients from 3.3.2 to 3.4.0.

---
updated-dependencies:
- dependency-name: org.apache.kafka:kafka-clients
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant