-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
修复ognl表达式获取字段值返回类型错误 #2965
Open
Allan-QLB
wants to merge
4
commits into
alibaba:master
Choose a base branch
from
Allan-QLB:ognl-property-get
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
修复ognl表达式获取字段值返回类型错误 #2965
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...rc/test/java/com/taobao/arthas/core/command/express/ArthasObjectPropertyAccessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.taobao.arthas.core.command.express; | ||
|
||
import com.taobao.arthas.core.advisor.Advice; | ||
import ognl.OgnlException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ArthasObjectPropertyAccessorTest { | ||
|
||
private Express express; | ||
|
||
@BeforeEach | ||
public void setUp () { | ||
Fetcher fetcher = new Fetcher().add(new Fetcher.Fetch() | ||
.add(new FlowContext("aa")) | ||
.add(new FlowContext("bb")) | ||
).add(new Fetcher.Fetch() | ||
.add(new FlowContext("cc")) | ||
.add(new FlowContext("dd")) | ||
.add(new FlowContext("ee")) | ||
); | ||
|
||
Object[] params = new Object[4]; | ||
params[0] = fetcher; | ||
Advice advice = Advice.newForAfterReturning(null, getClass(), null, null, params, null); | ||
express = ExpressFactory.unpooledExpress(null).bind(advice); | ||
} | ||
|
||
@Test | ||
void getPossibleProperty() throws ExpressException { | ||
assertInstanceOf(List.class, express.get("params[0].completedFetches")); | ||
assertEquals(2, ((List<?>) express.get("params[0].completedFetches")).size()); | ||
assertThrows(ExpressException.class, () -> express.is("params[0].hasCompletedFetches")); | ||
assertTrue(express.is("params[0].hasCompletedFetches()")); | ||
assertThrows(ExpressException.class, () -> express.is("params[0].getCompletedFetches")); | ||
assertTrue(express.is("params[0].getCompletedFetches()")); | ||
assertInstanceOf(Fetcher.Fetch.class, express.get("params[0].completedFetches[1]")); | ||
assertInstanceOf(List.class, express.get("params[0].completedFetches[1].flowContexts")); | ||
assertEquals(3, ((List) express.get("params[0].completedFetches[1].flowContexts")).size()); | ||
assertTrue(express.is("params[0].completedFetches[1].hasFlowContexts()")); | ||
assertTrue(express.is("params[0].completedFetches[1].getFlowContexts()")); | ||
assertInstanceOf(List.class, express.get("params[0].completedFetches[1].getFlowContexts1()")); | ||
assertInstanceOf(List.class, express.get("params[0].completedFetches.{flowContexts.{flowAttribute.bxApp}}")); | ||
assertIterableEquals(Arrays.asList( | ||
Arrays.asList("aa", "bb"), | ||
Arrays.asList("cc", "dd", "ee") | ||
), (Iterable<?>) express.get("params[0].completedFetches.{flowContexts.{flowAttribute.bxApp}}")); | ||
} | ||
|
||
|
||
|
||
} |
45 changes: 45 additions & 0 deletions
45
core/src/test/java/com/taobao/arthas/core/command/express/Fetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.taobao.arthas.core.command.express; | ||
|
||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Fetcher { | ||
private final List<Fetch> completedFetches = new ArrayList<>(); | ||
|
||
public boolean hasCompletedFetches() { | ||
return !completedFetches.isEmpty(); | ||
} | ||
|
||
public boolean getCompletedFetches() { | ||
return hasCompletedFetches(); | ||
} | ||
|
||
public Fetcher add(Fetch fetch) { | ||
completedFetches.add(fetch); | ||
return this; | ||
} | ||
|
||
public static class Fetch { | ||
private final List<FlowContext> flowContexts = new ArrayList<>(); | ||
public boolean hasFlowContexts() { | ||
return !flowContexts.isEmpty(); | ||
} | ||
|
||
public boolean getFlowContexts() { | ||
return !flowContexts.isEmpty(); | ||
} | ||
|
||
public List<FlowContext> getFlowContexts1() { | ||
return flowContexts; | ||
} | ||
|
||
public Fetch add(FlowContext flowContext) { | ||
flowContexts.add(flowContext); | ||
return this; | ||
} | ||
|
||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个修复貌似不合理。原始的 ognl是支持对 getter 函数用
.
去访问的。比如有一个getName
,可以用xxx.name
去获取。 这个修改会导致原来的OgnlRuntime.getMethodValue
的尝试没有了。另外,直接用
OgnlRuntime.getFieldValue
可能在高版本的 jdk 会有问题。