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

fix #1695

Merged
merged 1 commit into from
Nov 3, 2021
Merged

fix #1695

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
fix
  • Loading branch information
zhangayqian committed Jul 20, 2021
commit 56be272698c7419ab6cd1ee7b96b17efd4e9dce4
Original file line number Diff line number Diff line change
Expand Up @@ -1214,12 +1214,7 @@ private void setParam(PreparedStatement preparedState, int index, PrepareSqlRequ
throws SQLException {
boolean isNull = (null == param.getValue());

Class<?> clazz;
try {
clazz = Class.forName(param.getClassName());
} catch (ClassNotFoundException e) {
throw new InternalErrorException(e);
}
Class<?> clazz = getValidClass(param.getClassName());

Rep rep = Rep.of(clazz);

Expand Down Expand Up @@ -1288,6 +1283,25 @@ protected short getShort(String content) {
}
}

public Class<?> getValidClass(String className) {
Class<?> clazz;
try {
List<String> classList = new ArrayList<>();
Rep.VALUE_MAP.keySet().forEach(key -> {
classList.add(key.getName());
});
if (classList.contains(className)) {
clazz = Class.forName(className);
} else {
clazz = Class.forName("java.lang.Object");
}
logger.debug("Class parameter for sql is: " + clazz.getName());
} catch (ClassNotFoundException e) {
throw new InternalErrorException(e);
}
return clazz;
}

public void setCacheManager(CacheManager cacheManager) {
this.cacheManager = cacheManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,10 @@ public void testSyntaxError() {
Assert.assertTrue(wrapper == null || wrapper.get() == null);
}
}

@Test
public void testClassName() throws ClassNotFoundException {
Assert.assertEquals(Class.forName("java.lang.Object"), queryService.getValidClass("java.io.DataInputStream"));
Assert.assertEquals(Class.forName("java.lang.String"), queryService.getValidClass("java.lang.String"));
}
}