Skip to content

Commit

Permalink
[WINDUPRULE-1015] Rules for APIs deprecated for removal (#1012)
Browse files Browse the repository at this point in the history
* [WINDUPRULE-1015] Rules for APIs deprecated for removal

* [WINDUPRULE-1015] Divide rules and add Thread.stop() rule

* [WINDUPRULE-1015] Escape parenthesis

---------

Co-authored-by: PhilipCattanach <[email protected]>
  • Loading branch information
jmle and PhilipCattanach authored Jul 28, 2023
1 parent c509d75 commit 6ca369c
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="deprecation-openjdk18"
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 deprecated APIs in OpenJDK 18.
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final" />
</dependencies>
<sourceTechnology id="openjdk" versionRange="(,18)"/>
<targetTechnology id="openjdk" versionRange="[18,)"/>
</metadata>
<rules>
<!-- JDK18 -->
<rule id="deprecation-00000">
<when>
<javaclass references="javax.security.auth.Subject.doAs({*})">
<location>METHOD_CALL</location>
</javaclass>
</when>
<perform>
<hint title="Deprecated method in JDK 18 for removal in future release" effort="3" category-id="potential">
<message>
This `doAs` signature has been deprecated in JDK18 for removal in a future release.
</message>
</hint>
</perform>
</rule>
<rule id="deprecation-00005">
<when>
<javaclass references="java.lang.Thread.stop()">
<location>METHOD_CALL</location>
</javaclass>
</when>
<perform>
<hint title="Deprecated method in JDK 18 for removal in future release" effort="3" category-id="mandatory">
<message>
The `Thread.stop()` signature has been deprecated in JDK18 for removal in a future release.
</message>
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0"?>
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="deprecation-openjdk19"
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 deprecated APIs in OpenJDK 19.
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final" />
</dependencies>
<sourceTechnology id="openjdk" versionRange="(,19)"/>
<targetTechnology id="openjdk" versionRange="[19,)"/>
</metadata>
<rules>
<!-- JDK19 -->
<rule id="deprecation-00010">
<when>
<or>
<javaclass references="javax.swing.plaf.basic.BasicMenuItemUI.MouseInputHandler"/>
<javaclass references="javax.swing.plaf.basic.BasicScrollPaneUI.HSBChangeListener"/>
<javaclass references="javax.swing.plaf.basic.BasicScrollPaneUI.PropertyChangeHandler"/>
<javaclass references="javax.swing.plaf.basic.BasicScrollPaneUI.ViewportChangeHandler"/>
<javaclass references="javax.swing.plaf.basic.BasicScrollPaneUI.VSBChangeListener"/>
<javaclass references="javax.swing.plaf.basic.BasicDirectoryModel.intervalAdded({*})">
<location>METHOD_CALL</location>
</javaclass>
<javaclass references="javax.swing.plaf.basic.BasicDirectoryModel.intervalRemoved({*})">
<location>METHOD_CALL</location>
</javaclass>
<javaclass references="javax.swing.plaf.basic.BasicDirectoryModel.lt({*})">
<location>METHOD_CALL</location>
</javaclass>
<javaclass references="javax.swing.plaf.basic.BasicToolBarUI.createFloatingFrame({*})">
<location>METHOD_CALL</location>
</javaclass>
</or>
</when>
<perform>
<hint title="Deprecated class in JDK 19 for removal in future release" effort="3" category-id="mandatory">
<message>
Several classes under `javax.swing.plaf.basic` have been deprecated in JDK 19 for removal in a future release.
</message>
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="deprecation-openjdk20"
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 deprecated APIs in OpenJDK 20.
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final" />
</dependencies>
<sourceTechnology id="openjdk" versionRange="(,20)"/>
<targetTechnology id="openjdk" versionRange="[20,)"/>
</metadata>
<rules>
<!-- JDK20 -->
<rule id="deprecation-00020">
<when>
<or>
<javaclass references="javax.management.loading.MLet"/>
<javaclass references="javax.management.loading.MLetContent"/>
<javaclass references="javax.management.loading.MLetMBean"/>
<javaclass references="javax.management.loading.PrivateMLet"/>
<javaclass references="javax.lang.ThreadDeath"/>
</or>
</when>
<perform>
<hint title="Deprecated class in JDK 20 for removal in future release" effort="3" category-id="mandatory">
<message>
Several classes under `javax` have been deprecated in JDK 20 for removal in a future release.
</message>
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="deprecation-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 deprecated APIs in OpenJDK 21.
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final" />
</dependencies>
<sourceTechnology id="openjdk" versionRange="(,21)"/>
<targetTechnology id="openjdk" versionRange="[21,)"/>
</metadata>
<rules>
<!-- JDK21 -->
<rule id="deprecation-00030">
<when>
<or>
<javaclass references="javax.swing.plaf.synth.SynthLookAndFeel.load(java.net.URL)">
<location>METHOD_CALL</location>
</javaclass>
</or>
</when>
<perform>
<hint title="Deprecated class in JDK 21 for removal in future release" effort="3" category-id="mandatory">
<message>
The `load(URL)` method under `SynthLookAndFeel` has been deprecated in JDK 21 for removal in a future release.
</message>
</hint>
</perform>
</rule>

</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import javax.security.auth.Subject;
import javax.swing.plaf.basic.BasicDirectoryModel;
import javax.swing.plaf.basic.BasicMenuItemUI;
import javax.swing.plaf.basic.BasicScrollPaneUI;
import javax.swing.plaf.basic.BasicScrollPaneUI.PropertyChangeHandler;
import javax.swing.plaf.basic.BasicScrollPaneUI.HSBChangeListener;
import javax.swing.plaf.basic.BasicScrollPaneUI.ViewportChangeHandler;
import javax.swing.plaf.basic.BasicScrollPaneUI.VSBChangeListener;
import javax.swing.plaf.basic.BasicToolBarUI;
import java.net.URL;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import javax.management.loading.MLet;
import javax.management.loading.MLetContent;
import javax.management.loading.MLetMBean;
import javax.management.loading.PrivateMLet;
import javax.lang.ThreadDeath;
import javax.swing.plaf.synth.SynthLookAndFeel;

public class FinalizationDeprecation extends BasicMenuItemUI, BasicDirectoryModel {

public static void main(String[] args) {
MouseInputHandler mouseInputHandler = new BasicMenuItemUI.MouseInputHandler();

BasicDirectoryModel basicDirectoryModel = new BasicDirectoryModel(null);
basicDirectoryModel.intervalAdded(null);
basicDirectoryModel.intervalRemoved(null);
basicDirectoryModel.lt(null, null);

BasicToolBarUI basicToolBarUI = new BasicToolBarUI();
basicToolBarUI.createFloatingFrame(null);

Subject.doAs(new Subject(), new PrivilegedActionImpl());
Subject.doAs(new Subject(), new PrivilegedExceptionAction());

SynthLookAndFeel synthLookAndFeel = new SynthLookAndFeel();
URL url = new URL("hey");
synthLookAndFeel.load(url);

Thread thread = new Thread();
thread.stop();
}

public class PrivilegedActionImpl implements PrivilegedAction<String> {
@Override
public String run() {

}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<ruletest id="deprecation-openjdk18-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/deprecation</testDataPath>
<rulePath>../deprecation-openjdk18.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="deprecation-test-00000">
<when>
<not>
<iterable-filter size="2">
<hint-exists message="This `doAs` signature has been deprecated in JDK18 for removal in a future release." />
</iterable-filter>
</not>
</when>
<perform>
<fail message="deprecation-test-00000 - the hint was not found"/>
</perform>
</rule>
<rule id="deprecation-test-00005">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="The `Thread.stop\(\)` signature has been deprecated in JDK18 for removal in a future release." />
</iterable-filter>
</not>
</when>
<perform>
<fail message="deprecation-test-00005 - the hint was not found"/>
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<ruletest id="deprecation-openjdk19-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/deprecation</testDataPath>
<rulePath>../deprecation-openjdk19.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="deprecation-test-00010">
<when>
<not>
<iterable-filter size="9">
<hint-exists message="Several classes under `javax.swing.plaf.basic` have been deprecated in JDK 19 for removal*" />
</iterable-filter>
</not>
</when>
<perform>
<fail message="deprecation-test-00010 - the hint was not found"/>
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<ruletest id="deprecation-openjdk20-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/deprecation</testDataPath>
<rulePath>../deprecation-openjdk20.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="deprecation-test-00020">
<when>
<not>
<iterable-filter size="5">
<hint-exists message="Several classes under `javax` have been deprecated in JDK 20 for removal in a future release." />
</iterable-filter>
</not>
</when>
<perform>
<fail message="deprecation-test-00020 - the hint was not found"/>
</perform>
</rule>
<rule id="deprecation-test-00030">
<when>
<not>
<iterable-filter size="5">
<hint-exists message="Several classes under `javax` have been deprecated in JDK 20 for removal in a future release." />
</iterable-filter>
</not>
</when>
<perform>
<fail message="deprecation-test-00020 - the hint was not found"/>
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<ruletest id="deprecation-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/deprecation</testDataPath>
<rulePath>../deprecation-openjdk21.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="deprecation-test-00040">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="The `load\(URL\)` method under `SynthLookAndFeel` has been deprecated in JDK 21 for removal in a future release." />
</iterable-filter>
</not>
</when>
<perform>
<fail message="deprecation-test-00040 - the hint was not found"/>
</perform>
</rule>
</rules>
</ruleset>
</ruletest>

0 comments on commit 6ca369c

Please sign in to comment.