Skip to content

Commit e340d96

Browse files
ranuradhAnuRam123timtebeek
authored
Recipe to remove Thread.countStackFrames(). (#437)
* Adding recipe forJSE 17 migrations - DeprecatedCountStackFramesMethod * add some small fixes for yml and test * Delete src/main/java/org/openrewrite/java/migrate/jakarta/NewClassRecipe.java * Delete src/main/java/org/openrewrite/java/migrate/jakarta/SomeRecipe.java * Delete src/test/java/org/openrewrite/java/migrate/jakarta/SomeTest.java extra file committed * removed extra \ in the description * removing custom recipe using Integer.valueOf(0) to now remove the method when its not assigend to a variable * fixing small format * Fix indentation and use `recipeFromResources` * Add missing type to recipe --------- Co-authored-by: anuram <[email protected]> Co-authored-by: Tim te Beek <[email protected]>
1 parent dfbee69 commit e340d96

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

src/main/resources/META-INF/rewrite/java-version-17.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ recipeList:
4949
groupId: com.sonatype.clm
5050
artifactId: clm-maven-plugin
5151
newVersion: 2.47.6-01
52+
- org.openrewrite.java.migrate.DeprecatedCountStackFramesMethod
5253
- org.openrewrite.java.migrate.RemovedZipFinalizeMethods
5354
- org.openrewrite.java.migrate.RemovedSSLSessionGetPeerCertificateChainMethodImpl
5455
- org.openrewrite.java.migrate.SunNetSslPackageUnavailable
@@ -187,6 +188,19 @@ recipeList:
187188
fullyQualifiedConstantName: javax.management.remote.rmi.RMIConnectorServer.CREDENTIALS_FILTER_PATTERN
188189
---
189190
type: specs.openrewrite.org/v1beta/recipe
191+
name: org.openrewrite.java.migrate.DeprecatedCountStackFramesMethod
192+
displayName: Remove `Thread.countStackFrames()` method
193+
description: >
194+
`Thread.countStackFrames()` has been removed in Java SE 14 and has been changed in this release to unconditionally throw `UnsupportedOperationException`
195+
This recipe removes the usage of this method in your application as long as the method is not assigned to a variable.
196+
For more information on the Java SE 14 deprecation of this method, see https://bugs.java.com/bugdatabase/view_bug?bug_id=8205132.
197+
tags:
198+
- java17
199+
recipeList:
200+
- org.openrewrite.java.migrate.RemoveMethodInvocation:
201+
methodPattern: 'java.lang.Thread countStackFrames()'
202+
---
203+
type: specs.openrewrite.org/v1beta/recipe
190204
name: org.openrewrite.java.migrate.RemovedFileIOFinalizeMethods
191205
displayName: Replace `finalize` method in `java.io.FileInputStream` and `java.io.FileOutputStream`
192206
description: >
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.migrate;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.test.RecipeSpec;
21+
import org.openrewrite.test.RewriteTest;
22+
23+
import static org.openrewrite.java.Assertions.java;
24+
25+
class DeprecatedCountStackFramesMethodTest implements RewriteTest {
26+
@Override
27+
public void defaults(RecipeSpec spec) {
28+
spec.recipeFromResources("org.openrewrite.java.migrate.DeprecatedCountStackFramesMethod");
29+
}
30+
31+
@Test
32+
@DocumentExample
33+
void deprecatedCountStackFrameRemoveMethod() {
34+
rewriteRun(
35+
//language=java
36+
java(
37+
"""
38+
import java.lang.Thread;
39+
40+
public class Test {
41+
public static void main(String args[]) {
42+
Thread t1,t2 = new Thread();
43+
t1.countStackFrames();
44+
}
45+
}
46+
""",
47+
"""
48+
import java.lang.Thread;
49+
50+
public class Test {
51+
public static void main(String args[]) {
52+
Thread t1,t2 = new Thread();
53+
}
54+
}
55+
"""
56+
)
57+
);
58+
}
59+
60+
@Test
61+
void deprecatedCountStackFrameNoRemoval() {
62+
rewriteRun(
63+
//language=java
64+
java(
65+
"""
66+
import java.lang.Thread;
67+
68+
public class Test {
69+
public static void main(String args[]) {
70+
Thread t1,t2 = new Thread();
71+
int i = t1.countStackFrames();
72+
}
73+
}
74+
"""
75+
)
76+
);
77+
}
78+
}

0 commit comments

Comments
 (0)