File Servlets.java
has 771 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* Servlets.java
Purpose:
Description:
History:
Method browserInfo
has a Cognitive Complexity of 79 (exceeds 5 allowed). Consider refactoring. Open
private static void browserInfo(Map<String, Object> zk, String ua) {
if (ua != null) {
// ZK-1822: In locale Turkish, it can prevent 'I'.toLowerCase becomes 'i' without dot.
ua = ua.toLowerCase(Locale.ENGLISH);
if (_clientId != null) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getNormalPath
has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring. Open
public static String getNormalPath(String path) {
final StringBuffer sb = new StringBuffer(path);
final IntStack slashes = new IntStack(32); //most 32 slash in a path
slashes.push(-1);
int j = 0, colon = -100, dot1 = -100, dot2 = -100;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Servlets
has 45 methods (exceeds 20 allowed). Consider refactoring. Open
public class Servlets {
private static final Logger log = LoggerFactory.getLogger(Servlets.class);
private static ClientIdentifier _clientId;
private static final Pattern _rwebkit = Pattern.compile(".*(webkit)[ /]([\\w.]+).*"),
Method locate
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
@SuppressWarnings("unchecked")
public static final String locate(ServletContext ctx, ServletRequest request, String pgpath, Locator locator)
throws ServletException {
if (pgpath == null)
return pgpath;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method browserInfo
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static void browserInfo(Map<String, Object> zk, String ua) {
if (ua != null) {
// ZK-1822: In locale Turkish, it can prevent 'I'.toLowerCase becomes 'i' without dot.
ua = ua.toLowerCase(Locale.ENGLISH);
if (_clientId != null) {
Method getNormalPath
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static String getNormalPath(String path) {
final StringBuffer sb = new StringBuffer(path);
final IntStack slashes = new IntStack(32); //most 32 slash in a path
slashes.push(-1);
int j = 0, colon = -100, dot1 = -100, dot2 = -100;
Method browser
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private static boolean browser(String userAgent, String type) {
if (userAgent == null) //Bug ZK-1582: userAgent could be null if it is robot.
return false;
int last = (type = type.trim()).length();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method locate
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
@SuppressWarnings("unchecked")
public static final String locate(ServletContext ctx, ServletRequest request, String pgpath, Locator locator)
throws ServletException {
if (pgpath == null)
return pgpath;
Method generateURI
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public static final String generateURI(String uri, Map params, int mode) {
if (uri.startsWith("~"))
throw new IllegalArgumentException("~ctx not supported here: " + uri);
final int j = uri.indexOf('?');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getRequestDispatcher
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public static final RequestDispatcher getRequestDispatcher(ServletContext ctx, ServletRequest request, String uri,
Map params, int mode) throws ServletException {
final char cc = uri.length() > 0 ? uri.charAt(0) : (char) 0;
if (ctx == null || (cc != '/' && cc != '~')) { //... or relevant
if (request == null)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method generateURI
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static final String generateURI(String uri, Map params, int mode) {
if (uri.startsWith("~"))
throw new IllegalArgumentException("~ctx not supported here: " + uri);
final int j = uri.indexOf('?');
Method forward
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static final void forward(ServletContext ctx, ServletRequest request, ServletResponse response, String uri,
Map params, int mode) throws IOException, ServletException {
// if (log.isDebugEnabled()) log.debug("Forwarding "+uri);
//include or foward depending whether this page is included or not
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method browser
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static boolean browser(String userAgent, String type) {
if (userAgent == null) //Bug ZK-1582: userAgent could be null if it is robot.
return false;
int last = (type = type.trim()).length();
Method include
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public static final void include(ServletContext ctx, ServletRequest request, ServletResponse response, String uri,
Map params, int mode) throws IOException, ServletException {
Method getExtension
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static final String getExtension(String path, boolean lastOnly) {
if (lastOnly)
return getExtension(path);
if (path == null)
return null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if (slashes.isEmpty()) {
slashes.push(-1);
}
Method forward
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public static final void forward(ServletContext ctx, ServletRequest request, ServletResponse response, String uri,
Map params, int mode) throws IOException, ServletException {
Avoid deeply nested control flow statements. Open
if (preslash == 0) { //special case "/../"
throw new IllegalArgumentException("Illegal path: " + path);
}
Avoid deeply nested control flow statements. Open
if (j >= 0) {
int k = ua.indexOf('.', j += 8);
if (k >= 0) {
for (int len = ua.length(); ++k < len;) {
final char cc = ua.charAt(k);
Method getRequestDispatcher
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static final RequestDispatcher getRequestDispatcher(ServletContext ctx, ServletRequest request, String uri,
Map params, int mode) throws ServletException {
Method getResource
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static final URL getResource(ServletContext ctx, String uri) throws UnsupportedEncodingException {
try {
if (uri != null && uri.toLowerCase(java.util.Locale.ENGLISH).startsWith("file://")) {
final File file = new File(new URI(uri));
return file.exists() ? file.toURI().toURL() : null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getResourceAsStream
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static final InputStream getResourceAsStream(ServletContext ctx, String uri) throws IOException {
try {
if (uri != null && uri.toLowerCase(java.util.Locale.ENGLISH).startsWith("file://")) {
final File file = new File(new URI(uri));
return file.exists() ? new BufferedInputStream(new FileInputStream(file)) : null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return false; //not matched for Bug ZK-1930
Avoid too many return
statements within this method. Open
return qstr != null ? uri + qstr : uri;
Avoid too many return
statements within this method. Open
return equals ? v1 == v2 : v1 >= v2;
Avoid too many return
statements within this method. Open
return;
Method getUserAgent
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static final String getUserAgent(ServletRequest req) {
if (req instanceof HttpServletRequest) {
String s = ((HttpServletRequest) req).getHeader("user-agent");
if (s != null) {
String cache = (String) req.getAttribute("$$zkagent$$");
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method include
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static final void include(ServletContext ctx, ServletRequest request, ServletResponse response, String uri,
Map params, int mode) throws IOException, ServletException {
// if (log.isDebugEnabled()) log.debug("Including "+uri+" at "+ctx);
//Note: we don't optimize the include to call ClassWebResource here
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 3 locations. Consider refactoring. Open
if (j >= 0) {
ctxroot = "/" + uri.substring(1, j);
_uri = uri.substring(j);
} else {
ctxroot = "/" + uri.substring(1);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 66.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
private URIIndex(String uri, Locale locale) {
if (uri == null || locale == null)
throw new IllegalArgumentException("null");
_uri = uri;
_locale = locale;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 45.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76