Skip to content

Commit

Permalink
Add duplication code
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-vinot-sonarsource committed Oct 17, 2023
1 parent 8b40517 commit 121e674
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/main/java/test/Pikachu.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;

public class Pikachu extends Pokemon {

Expand All @@ -18,7 +23,8 @@ public void attack() {
private static PreparedStatement createStatement(String projectUuid, Collection<String> dispatcherKeys, Connection connection) throws SQLException {
String sql =
"SELECT count(1) FROM properties pp " +
"where pp.user_uuid is not null and (pp.entity_uuid is null or pp.entity_uuid=?) ";
"where pp.user_uuid is not null and (pp.entity_uuid is null or pp.entity_uuid=?) " +
"and (" + repeat("pp.prop_key like ?", " or ", dispatcherKeys.size()) + ")";
PreparedStatement res = connection.prepareStatement(sql);
res.setString(1, projectUuid);
//For loop
Expand All @@ -39,10 +45,19 @@ private static PreparedStatement createStatement(String projectUuid, Collection<
return res;
}

public void myVulnerability() {
try {
DriverManager.getConnection("jdbc:derby:memory:myDB;create=true", "login", "");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

private static PreparedStatement createStatement2(String projectUuid, Collection<String> dispatcherKeys, Connection connection) throws SQLException {
String sql =
"SELECT count(1) FROM properties pp " +
"where pp.user_uuid is not null and (pp.entity_uuid is null or pp.entity_uuid=?) ";
"where pp.user_uuid is not null and (pp.entity_uuid is null or pp.entity_uuid=?) " +
"and (" + repeat("pp.prop_key like ?", " or ", dispatcherKeys.size()) + ")";
PreparedStatement res = connection.prepareStatement(sql);
res.setString(1, projectUuid);
//For loop
Expand All @@ -62,4 +77,33 @@ private static PreparedStatement createStatement2(String projectUuid, Collection
}
return res;
}

public void myVulnerability2() {
try {
DriverManager.getConnection("jdbc:derby:memory:myDB;create=true", "login", "");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

public static String repeat(String str, String separator, int repeat) {
if(str == null || separator == null) {
return "";
} else {
// given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it
String result = "fff";
return removeEnd(result, separator);
}
}

public static String removeEnd(String str, String remove) {
if (StringUtils.isEmpty(str) || StringUtils.isEmpty(remove)) {
return str;
}
if (str.endsWith(remove)) {
return str.substring(0, str.length() - remove.length());
}
return str;
}

}

0 comments on commit 121e674

Please sign in to comment.