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

[WINDUPRULE-1014] Add rules for several removed APIs #1015

Merged
merged 9 commits into from
Jul 31, 2023
75 changes: 75 additions & 0 deletions rules/rules-reviewed/openjdk21/openjdk17/removed-apis.windup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0"?>
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="removed-apis-openjdk21"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<metadata>
<description>
This ruleset provides analysis regarding removed APIs in OpenJDK 18 to 21.
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final" />
</dependencies>
<targetTechnology id="openjdk" versionRange="[18,)"/>
</metadata>
<rules>
<rule id="removed-apis-00000">
<when>
<or>
<javaclass references="java.awt.color.ICC_Profile.finalize()">
<location>METHOD_CALL</location>
</javaclass>
<javaclass references="java.awt.image.ColorModel.finalize()">
<location>METHOD_CALL</location>
</javaclass>
<javaclass references="java.awt.image.IndexColorModel.finalize()">
<location>METHOD_CALL</location>
</javaclass>
</or>
</when>
<perform>
<hint title="These finalization methods have been removed" effort="3" category-id="mandatory">
<message>
This finalization method has been removed between JDK 18 and 21 and must be removed from the code.
</message>
</hint>
</perform>
</rule>
<rule id="removed-apis-00005">
<when>
<javaclass references="java.lang.ThreadGroup.allowThreadSuspension({*})">
<location>METHOD_CALL</location>
</javaclass>
</when>
<perform>
<hint title="Method java.lang.ThreadGroup.allowThreadSuspension() has been removed" effort="1" category-id="mandatory">
<message>
The `java.lang.ThreadGroup.allowThreadSuspension` method has been removed and cannot be used anymore.
</message>
</hint>
</perform>
</rule>
<rule id="removed-apis-00010">
<when>
<javaclass references="java.lang.Compiler"/>
</when>
<perform>
<hint title="Method java.lang.Compiler has been removed" effort="3" category-id="mandatory">
<message>
The `java.lang.Compiler` method has been removed and cannot be used anymore.
</message>
</hint>
</perform>
</rule>
<rule id="removed-apis-00015">
<when>
<javaclass references="javax.management.remote.rmi.RMIIIOPServerImpl"/>
</when>
<perform>
<hint title="javax.management.remote.rmi.RMIIIOPServerImpl" effort="3" category-id="mandatory">
<message>
The `javax.management.remote.rmi.RMIIIOPServerImpl` method has been removed and cannot be used anymore.
</message>
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import javax.imageio.stream.FileImageOutputStream;
import java.io.File;

public class FinalizationDeprecation extends Object {

public static void main(String[] args) {
FinalizationDeprecation o1 = new FinalizationDeprecation();
o1.finalize();

Runtime runtime = Runtime.getRuntime();
runtime.runFinalization();

System.runFinalization();

FileImageOutputStream stream = new FileImageOutputStream(new File("hey"));
stream.finalize();
}

@Override
protected void finalize() throws Throwable {
super.finalize();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.awt.color.ICC_Profile;
import java.awt.image.ColorModel;
import java.awt.image.IndexColorModel;
import java.lang.Compiler;
import javax.management.remote.rmi.RMIIIOPServerImpl;

public class FinalizationDeprecation extends Object {

public static void main(String[] args) {
ICC_Profile profile = ICC_Profile.getInstance(1);
profile.finalize();

ColorModel colorModel = ColorModel.getRGBdefault();
colorModel.finalize();

IndexColorModel indexColorModel = IndexColorModel.getRGBdefault();
indexColorModel.finalize();

ThreadGroup threadGroup = new ThreadGroup();
threadGroup.allowThreadSuspension();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ruletest id="finalization-deprecation-test"
xmlns="http://windup.jboss.org/schema/jboss-ruleset"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<testDataPath>data</testDataPath>
<testDataPath>data/finalization-deprecation</testDataPath>
<rulePath>../finalization-deprecation.windup.xml</rulePath>
<ruleset>
<rules>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0"?>
<ruletest id="removed-apis-openjdk21-test"
xmlns="http://windup.jboss.org/schema/jboss-ruleset"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<testDataPath>data/removed-apis</testDataPath>
<rulePath>../removed-apis.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="removed-apis-test-00000">
<when>
<not>
<iterable-filter size="3">
<hint-exists message="This finalization method has been removed between JDK 18 and 21 and must be*" />
</iterable-filter>
</not>
</when>
<perform>
<fail message="removed-apis-test-00000 - the hint was not found"/>
</perform>
</rule>
<rule id="removed-apis-test-00005">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="The `java.lang.ThreadGroup.allowThreadSuspension` method has been removed and cannot be used anymore." />
</iterable-filter>
</not>
</when>
<perform>
<fail message="removed-apis-test-00005 - the hint was not found"/>
</perform>
</rule>
<rule id="removed-apis-test-00010">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="The `java.lang.Compiler` method has been removed and cannot be used anymore." />
</iterable-filter>
</not>
</when>
<perform>
<fail message="removed-apis-test-00010 - the hint was not found"/>
</perform>
</rule>
<rule id="removed-apis-test-00015">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="The `javax.management.remote.rmi.RMIIIOPServerImpl` method has been removed and cannot be used anymore." />
</iterable-filter>
</not>
</when>
<perform>
<fail message="removed-apis-test-00015 - the hint was not found"/>
</perform>
</rule>
</rules>
</ruleset>
</ruletest>