使用混淆器混淆 JAXB 代码期间出现 IllegalAnnotationsException

IllegalAnnotationsException during obfuscating JAXB code with proguard

我想用混淆器混淆 JAXB 代码。这是完整的 Java class 代码:

  import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlType;

@XmlType(propOrder =
{
    "setting", "subsystems"
})
@XmlAccessorType(XmlAccessType.FIELD)
public class ProfileImpl implements Profile
{
    @XmlAttribute
    private String name;
    @XmlAttribute
    private final String version;
    @XmlElementWrapper(name = "subsystems")
    @XmlElement(name = "subsystem")
    private List<SubsystemImpl> subsystems;
    private SettingImpl setting;

    public ProfileImpl()
    {
        this.version = "1.0";
        this.name = "default";
    }

    public ProfileImpl(String name, SettingImpl setting, List<SubsystemImpl> subsystems, String version)
    {
        this.name = name;
        this.setting = setting;
        this.version = version;
        this.subsystems = subsystems;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public List<SubsystemImpl> getSubsystems()
    {
        return subsystems;
    }

    public void setSubsystems(List<SubsystemImpl> subsystems)
    {
        this.subsystems = subsystems;
    }

    public SettingImpl getSetting()
    {
        return setting;
    }

    public void setSetting(SettingImpl setting)
    {
        this.setting = setting;
    }
}

但是当我 运行 我得到代码时:

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 4 counts of IllegalAnnotationExceptions
Property c is present but not specified in @XmlType.propOrder
        this problem is related to the following location:
                at private java.util.List org.settings.loader.osgi.impl.jaxb.ProfileImpl.c
                at org.settings.loader.osgi.impl.jaxb.ProfileImpl
                at private java.util.List org.settings.loader.osgi.impl.jaxb.f.b
                at org.settings.loader.osgi.impl.jaxb.f
Property d is present but not specified in @XmlType.propOrder
        this problem is related to the following location:
                at private org.settings.loader.osgi.impl.jaxb.d org.settings.loader.osgi.impl.jaxb.ProfileImpl.d
                at org.settings.loader.osgi.impl.jaxb.ProfileImpl
                at private java.util.List org.settings.loader.osgi.impl.jaxb.f.b
                at org.settings.loader.osgi.impl.jaxb.f

我该如何解决这个问题?

我尝试了这个 Proguard 配置以跳过 Class 混淆:

<option>-keep public class org.settings.loader.osgi.impl.jaxb.ProfileImpl{public *; private *;} -keepattributes Exceptions, *Annotation*, InnerClasses, Signature, SourceFile, EnclosingMethod -dontshrink -dontoptimize -keepparameternames</option>

请在 prop 顺序中添加 "name" 和 "version",因为访问类型定义为 Field

为了混淆处理注释,请尝试将以下内容添加到参数中

-keep public class javax.xml.bind.**
-keep public class org.settings.loader.osgi.impl.jaxb.ProfileImpl implements org.settings.loader.osgi.impl.jaxb.Profile
-keepattributes *Annotation*

http://proguard.sourceforge.net/manual/examples.html#annotations

更新

我冒昧地修改了您的代码,如下所示。 请检查此修改后并在代码后面包含参数是否有任何不同。

public class ProfileImpl implements Profile
{
    private String name;
    private final String version;
    private List<SubsystemImpl> subsystems;
    private SettingImpl setting;

    public ProfileImpl(){
        this.version = "1.0";
        this.name = "default";
    }

    public ProfileImpl(String name, SettingImpl setting, List<SubsystemImpl> subsystems, String version){
        this.name = name;
        this.setting = setting;
        this.version = version;
        this.subsystems = subsystems;
    }

    @XmlAttribute(name = "name")
    public String getName(){
        return name;
    }

    public void setName(String name){
        this.name = name;
    }

    @XmlAttribute(name = "version")
    public String getVersion(){
        return version;
    }

    public void setVersion(String version){
        this.version = version;
    }

    @XmlElementWrapper(name = "subsystems")
    @XmlElement(name = "subsystem")
    public List<SubsystemImpl> getSubsystems(){
        return subsystems;
    }

    public void setSubsystems(List<SubsystemImpl> subsystems){
        this.subsystems = subsystems;
    }

    public SettingImpl getSetting(){
        return setting;
    }

    public void setSetting(SettingImpl setting){
        this.setting = setting;
    }
}