Migrates from Netty 3.2.x to Netty 4.1.x
org.openrewrite.netty.UpgradeNetty_3_2_to_4_1
Migrate applications to the latest Netty 4.1.x release.
Tags
Recipe source
GitHub: netty-3_2_to_4_1.yml, Issue Tracker, Maven Central
This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.
This recipe is available under the Apache License Version 2.0.
Definition
- Recipe List
- Yaml Recipe List
- Change method name
- methodPattern:
*..* channelOpen(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelStateEvent) - newMethodName:
channelActive
- methodPattern:
- Change method name
- methodPattern:
*..* channelClosed(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelStateEvent) - newMethodName:
channelInactive
- methodPattern:
- Change method name
- methodPattern:
*..* messageReceived(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.MessageEvent) - newMethodName:
channelRead
- methodPattern:
- Change parameter type for a method declaration
- methodPattern:
*..* channelRead(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.MessageEvent) - parameterType:
java.lang.Object - parameterIndex:
1
- methodPattern:
- Change method name
- methodPattern:
org.jboss.netty.channel.ChannelHandlerContext getChannel() - newMethodName:
channel
- methodPattern:
- Change method name
- methodPattern:
org.jboss.netty.channel.ChannelHandlerContext getPipeline() - newMethodName:
pipeline
- methodPattern:
- Change method name
- methodPattern:
org.jboss.netty.channel.Channel getPipeline() - newMethodName:
pipeline
- methodPattern:
- Change method name
- methodPattern:
org.jboss.netty.channel.Channel isConnected() - newMethodName:
isActive
- methodPattern:
- Change method name
- methodPattern:
org.jboss.netty.channel.Channel getLocalAddress() - newMethodName:
localAddress
- methodPattern:
- Change method name
- methodPattern:
org.jboss.netty.channel.Channel getRemoteAddress() - newMethodName:
remoteAddress
- methodPattern:
- Change method name
- methodPattern:
org.jboss.netty.channel.Channel getCloseFuture() - newMethodName:
closeFuture
- methodPattern:
- Change method name
- methodPattern:
org.jboss.netty.channel.ChannelFuture getChannel() - newMethodName:
channel
- methodPattern:
- Change method name
- methodPattern:
org.jboss.netty.channel.ChannelFuture getCause() - newMethodName:
cause
- methodPattern:
- Remove ChannelStateEvent parameter from handler methods
- Migrate Channel.setReadable(boolean) to Channel.config().setAutoRead(boolean)
- Replace annotation
- annotationPatternToReplace:
@org.jboss.netty.channel.ChannelPipelineCoverage(org.jboss.netty.channel.ChannelPipelineCoverage.ONE) - annotationTemplateToInsert:
@io.netty.channel.ChannelHandler.Sharable - classpathResourceName:
netty-transport
- annotationPatternToReplace:
- Change type
- oldFullyQualifiedTypeName:
org.jboss.netty.channel.SimpleChannelHandler - newFullyQualifiedTypeName:
io.netty.channel.ChannelInboundHandlerAdapter
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
org.jboss.netty.channel.SimpleChannelUpstreamHandler - newFullyQualifiedTypeName:
io.netty.channel.ChannelInboundHandlerAdapter
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
org.jboss.netty.handler.codec.frame.CorruptedFrameException - newFullyQualifiedTypeName:
io.netty.handler.codec.CorruptedFrameException
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
org.jboss.netty.buffer.ChannelBuffer - newFullyQualifiedTypeName:
io.netty.buffer.ByteBuf
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
org.jboss.netty.buffer.ChannelBuffers - newFullyQualifiedTypeName:
io.netty.buffer.Unpooled
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
org.jboss.netty.channel.ExceptionEvent - newFullyQualifiedTypeName:
java.lang.Throwable
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
org.jboss.netty.handler.codec.oneone.OneToOneDecoder - newFullyQualifiedTypeName:
io.netty.handler.codec.MessageToMessageDecoder
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
org.jboss.netty.util.ObjectSizeEstimator - newFullyQualifiedTypeName:
io.netty.channel.MessageSizeEstimator
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
org.jboss.netty.util.DefaultObjectSizeEstimator - newFullyQualifiedTypeName:
io.netty.channel.DefaultMessageSizeEstimator
- oldFullyQualifiedTypeName:
- Migrate StringEncoder(String) to StringEncoder(StandardCharsets)
- Rename package name
- oldPackageName:
org.jboss.netty.logging - newPackageName:
io.netty.util.internal.logging - recursive:
true
- oldPackageName:
- Rename package name
- oldPackageName:
org.jboss.netty - newPackageName:
io.netty - recursive:
true
- oldPackageName:
- Change Maven dependency
- oldGroupId:
org.jboss.netty - oldArtifactId:
netty - newGroupId:
io.netty - newArtifactId:
netty-all - newVersion:
4.1.x
- oldGroupId:
- Replace Channels.fireMessageReceived(..) with ctx.fireChannelRead(e)
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.netty.UpgradeNetty_3_2_to_4_1
displayName: Migrates from Netty 3.2.x to Netty 4.1.x
description: |
Migrate applications to the latest Netty 4.1.x release.
tags:
- netty
recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: *..* channelOpen(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelStateEvent)
newMethodName: channelActive
- org.openrewrite.java.ChangeMethodName:
methodPattern: *..* channelClosed(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelStateEvent)
newMethodName: channelInactive
- org.openrewrite.java.ChangeMethodName:
methodPattern: *..* messageReceived(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.MessageEvent)
newMethodName: channelRead
- org.openrewrite.java.spring.ChangeMethodParameter:
methodPattern: *..* channelRead(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.MessageEvent)
parameterType: java.lang.Object
parameterIndex: 1
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.jboss.netty.channel.ChannelHandlerContext getChannel()
newMethodName: channel
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.jboss.netty.channel.ChannelHandlerContext getPipeline()
newMethodName: pipeline
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.jboss.netty.channel.Channel getPipeline()
newMethodName: pipeline
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.jboss.netty.channel.Channel isConnected()
newMethodName: isActive
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.jboss.netty.channel.Channel getLocalAddress()
newMethodName: localAddress
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.jboss.netty.channel.Channel getRemoteAddress()
newMethodName: remoteAddress
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.jboss.netty.channel.Channel getCloseFuture()
newMethodName: closeFuture
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.jboss.netty.channel.ChannelFuture getChannel()
newMethodName: channel
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.jboss.netty.channel.ChannelFuture getCause()
newMethodName: cause
- org.openrewrite.java.netty.upgrade._3_2_to_4_1_.RemoveChannelStateEventParameter
- org.openrewrite.java.netty.upgrade._3_2_to_4_1_.ChannelSetReadableToAutoRead
- org.openrewrite.java.ReplaceAnnotation:
annotationPatternToReplace: @org.jboss.netty.channel.ChannelPipelineCoverage(org.jboss.netty.channel.ChannelPipelineCoverage.ONE)
annotationTemplateToInsert: @io.netty.channel.ChannelHandler.Sharable
classpathResourceName: netty-transport
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.jboss.netty.channel.SimpleChannelHandler
newFullyQualifiedTypeName: io.netty.channel.ChannelInboundHandlerAdapter
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.jboss.netty.channel.SimpleChannelUpstreamHandler
newFullyQualifiedTypeName: io.netty.channel.ChannelInboundHandlerAdapter
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.jboss.netty.handler.codec.frame.CorruptedFrameException
newFullyQualifiedTypeName: io.netty.handler.codec.CorruptedFrameException
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.jboss.netty.buffer.ChannelBuffer
newFullyQualifiedTypeName: io.netty.buffer.ByteBuf
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.jboss.netty.buffer.ChannelBuffers
newFullyQualifiedTypeName: io.netty.buffer.Unpooled
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.jboss.netty.channel.ExceptionEvent
newFullyQualifiedTypeName: java.lang.Throwable
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.jboss.netty.handler.codec.oneone.OneToOneDecoder
newFullyQualifiedTypeName: io.netty.handler.codec.MessageToMessageDecoder
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.jboss.netty.util.ObjectSizeEstimator
newFullyQualifiedTypeName: io.netty.channel.MessageSizeEstimator
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.jboss.netty.util.DefaultObjectSizeEstimator
newFullyQualifiedTypeName: io.netty.channel.DefaultMessageSizeEstimator
- org.openrewrite.java.netty.upgrade._3_2_to_4_1_.StringEncoderToStandardCharsets
- org.openrewrite.java.ChangePackage:
oldPackageName: org.jboss.netty.logging
newPackageName: io.netty.util.internal.logging
recursive: true
- org.openrewrite.java.ChangePackage:
oldPackageName: org.jboss.netty
newPackageName: io.netty
recursive: true
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: org.jboss.netty
oldArtifactId: netty
newGroupId: io.netty
newArtifactId: netty-all
newVersion: 4.1.x
- org.openrewrite.java.netty.upgrade._3_2_to_4_1_.ReplaceChannelsFireMessageReceived
Examples
Example 1
UpgradeNetty_3_2_to_4_1Test#changeMethodSignature
- java
- Diff
Before
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
class Test {
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {}
}
After
import io.netty.channel.ChannelHandlerContext;
class Test {
public void channelActive(ChannelHandlerContext ctx) throws Exception {}
}
@@ -1,2 +1,1 @@
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelStateEvent;
+import io.netty.channel.ChannelHandlerContext;
@@ -5,1 +4,1 @@
class Test {
- public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {}
+ public void channelActive(ChannelHandlerContext ctx) throws Exception {}
}
Example 2
UpgradeNetty_3_2_to_4_1Test#changeMethodSignature
- java
- Diff
Before
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
class Test {
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {}
}
After
import io.netty.channel.ChannelHandlerContext;
class Test {
public void channelActive(ChannelHandlerContext ctx) throws Exception {}
}
@@ -1,2 +1,1 @@
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelStateEvent;
+import io.netty.channel.ChannelHandlerContext;
@@ -5,1 +4,1 @@
class Test {
- public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {}
+ public void channelActive(ChannelHandlerContext ctx) throws Exception {}
}
Usage
This recipe has no required configuration options. Users of Moderne can run it via the Moderne CLI.
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe UpgradeNetty_3_2_to_4_1
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite.recipe:rewrite-netty:0.8.0
See how this recipe works across multiple open-source repositories
Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.
Data Tables
- SourcesFileResults
- SearchResults
- SourcesFileErrors
- RecipeRunStats
- MavenMetadataFailures
Source files that had results
org.openrewrite.table.SourcesFileResults
Source files that were modified by the recipe run.
| Column Name | Description |
|---|---|
| Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
| Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
| Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
| Recipe that made changes | The specific recipe that made a change. |
| Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
| Cycle | The recipe cycle in which the change was made. |
Source files that had search results
org.openrewrite.table.SearchResults
Search results that were found during the recipe run.
| Column Name | Description |
|---|---|
| Source path of search result before the run | The source path of the file with the search result markers present. |
| Source path of search result after run the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
| Result | The trimmed printed tree of the LST element that the marker is attached to. |
| Description | The content of the description of the marker. |
| Recipe that added the search marker | The specific recipe that added the Search marker. |
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrors
The details of all errors produced by a recipe run.
| Column Name | Description |
|---|---|
| Source path | The file that failed to parse. |
| Recipe that made changes | The specific recipe that made a change. |
| Stack trace | The stack trace of the failure. |
Recipe performance
org.openrewrite.table.RecipeRunStats
Statistics used in analyzing the performance of recipes.
| Column Name | Description |
|---|---|
| The recipe | The recipe whose stats are being measured both individually and cumulatively. |
| Source file count | The number of source files the recipe ran over. |
| Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. |
| Cumulative scanning time (ns) | The total time spent across the scanning phase of this recipe. |
| Max scanning time (ns) | The max time scanning any one source file. |
| Cumulative edit time (ns) | The total time spent across the editing phase of this recipe. |
| Max edit time (ns) | The max time editing any one source file. |
Maven metadata failures
org.openrewrite.maven.table.MavenMetadataFailures
Attempts to resolve maven metadata that failed.
| Column Name | Description |
|---|---|
| Group id | The groupId of the artifact for which the metadata download failed. |
| Artifact id | The artifactId of the artifact for which the metadata download failed. |
| Version | The version of the artifact for which the metadata download failed. |
| Maven repository | The URL of the Maven repository that the metadata download failed on. |
| Snapshots | Does the repository support snapshots. |
| Releases | Does the repository support releases. |
| Failure | The reason the metadata download failed. |