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

Added jre17AgentMainPreMainPublic recipes #296

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/resources/META-INF/rewrite/java-version-17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ recipeList:
- org.openrewrite.java.migrate.DeprecatedJavaxSecurityCert
- org.openrewrite.java.migrate.DeprecatedLogRecordThreadID
- org.openrewrite.java.migrate.RemovedLegacySunJSSEProviderName
- org.openrewrite.java.migrate.Jre17AgentMainPreMainPublic

---
type: specs.openrewrite.org/v1beta/recipe
Expand Down Expand Up @@ -89,3 +90,23 @@ recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: java.util.logging.LogRecord setThreadID(int)
newMethodName: setLongThreadID
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.Jre17AgentMainPreMainPublic
displayName: Set visibility of `premain` and `agentmain` methods to `public`
description: Check for a behavior change in Java agents.
tags:
- java17
recipeList:
- org.openrewrite.java.ChangeMethodAccessLevel:
methodPattern: "*..* agentmain(java.lang.String)"
newAccessLevel: public
- org.openrewrite.java.ChangeMethodAccessLevel:
methodPattern: "*..* agentmain(java.lang.String, java.lang.instrument.Instrumentation)"
newAccessLevel: public
- org.openrewrite.java.ChangeMethodAccessLevel:
methodPattern: "*..* premain(java.lang.String)"
newAccessLevel: public
- org.openrewrite.java.ChangeMethodAccessLevel:
methodPattern: "*..* premain(java.lang.String, java.lang.instrument.Instrumentation)"
newAccessLevel: public
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,94 @@ void notNeedToUpgradeMavenCompilerPluginToSupportReleaseTag() {
8)
);
}

@Test
void testAgentMainPreMainPublicApp() {
rewriteRun(
version(
//language=java
java(
"""
package com.test;

import java.lang.instrument.Instrumentation;

public class AgentMainPreMainPublicApp {

private static void premain(String agentArgs) {
//This should flag
}

public static void premain(String agentArgs, Instrumentation inst) {
//This shouldn't flag
}

public static void premain(String agentArgs, Instrumentation inst, String foo) {
//This shouldn't flag
}

private static void premain1(String agentArgs) {
//This shouldn't flag
}

protected void agentmain(String agentArgs) {
//This should flag
}

static void agentmain(String agentArgs, Instrumentation inst) {
//This should flag
}

private static void agentmain(String agentArgs, Instrumentation inst, String foo) {
//This shouldn't flag
}

private static void agentmain(String agentArgs, String inst) {
//This shouldn't flag
}
}
""",
"""
package com.test;

import java.lang.instrument.Instrumentation;

public class AgentMainPreMainPublicApp {

public static void premain(String agentArgs) {
//This should flag
}

public static void premain(String agentArgs, Instrumentation inst) {
//This shouldn't flag
}

public static void premain(String agentArgs, Instrumentation inst, String foo) {
//This shouldn't flag
}

private static void premain1(String agentArgs) {
//This shouldn't flag
}

public void agentmain(String agentArgs) {
//This should flag
}

public static void agentmain(String agentArgs, Instrumentation inst) {
//This should flag
}

private static void agentmain(String agentArgs, Instrumentation inst, String foo) {
//This shouldn't flag
}

private static void agentmain(String agentArgs, String inst) {
//This shouldn't flag
}
}
"""
), 17)
);
}
}
Loading