UseVarForGenericMethodInvocations 'mvn rewrite:run' crash
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Tìm recipe UseVarForGenericMethodInvocations và phần triển khai JavaTemplate, sau đó tái hiện lỗi crash bằng test case Java được nêu trong issue. Công việc hoàn tất khi lời gọi phương thức generic được chuyển đổi thành var mà không xảy ra exception và đầu ra mã nguồn mong đợi được tạo ra.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What version of OpenRewrite are you using?
Latest 3.4.0
What is the smallest, simplest way to reproduce the problem?
@Test
public void useVarBug() {
rewriteRun(
spec -> spec.recipe(new UseVarForGenericMethodInvocations()),
version(
//language=java
java(
"""
import java.util.Optional;
class A {
<T extends Number> void test(T element) {
Optional<T> o = Optional.of(element);
}
}
""",
"""
import java.util.Optional;
class A {
<T extends Number> void test(T element) {
var o = Optional.of(element);
}
}
"""), 17));
}
What did you expect to see?
Replace variable with var
What did you see instead?
It crashes.
What is the full stack trace of any errors you encountered?
org.openrewrite.internal.RecipeRunException: java.lang.IllegalArgumentException: Expected a template that would generate exactly one statement to replace one statement, but generated 2. Template:
var o = __P__.<java.util.Optional<T extends java.lang.Number>>/*__p1__*/p()
Substitutions:
Substitutions(code=var #{} = #{any()}, parameters=[o, Optional.of(element)], propertyPlaceholderHelper=org.openrewrite.internal.PropertyPlaceholderHelper@3ee0b4f7)
Statement:
Optional<T> o = Optional.of(element)
Are you interested in contributing a fix to OpenRewrite
I think there are 2 issues here.
In the JavaTemplate implementation:
var o = __P__.<java.util.Optional<T extends java.lang.Number>>/*__p1__*/p()
should be
var o = __P__.<java.util.Optional<T>>/*__p1__*/p()
and this would work by making the template in UseVarForGenericMethodInvocations context sensitive.
But maybe, for this recipe, it would be best to do the "transformation" by hand, instead of using JavaTemplate?
- Ngôn ngữ chính
- Java
- Star
- 156
- Fork
- 129
- Merge trung bình
- 7 giờ 12 phút
- Pull request đã merge (30 ngày)
- 43
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openrewrite/rewrite-migrate-java
-
bug
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 40/100
openrewrite/rewrite-migrate-java#1292 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
openrewrite/rewrite-migrate-java#1289 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
openrewrite/rewrite-migrate-java#1246 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 32/100
openrewrite/rewrite-migrate-java#1227 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
OptionalNotPresentToIsEmpty rewrites `!isPresent()` on a non-`java.util.Optional` type, producing uncompilable `isEmpty()`Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
openrewrite/rewrite-migrate-java#1146 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openrewrite/rewrite-migrate-java
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug new windows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
iOS podspec depends on `React-Codegen`, which resolves to an unrelated pod on CocoaPods trunkĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
GantMan/jail-monkey#380 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
objectionary/jucs#145 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
objectionary/lints#1559 ·
Maintainer thường phản hồi trong vòng 2 ngày