为什么 SonarQube 抱怨这部分代码?
SonarQube 说: 更改此条件,使其不总是评估为“假”
但是我似乎无法理解为什么条件总是错误的?事实上,实际上并非如此,我只是在调试模式下再次重新运行了这部分,它运行良好,它确实进入了内部,并且大多数情况下条件都不是假的。
这是代码部分:
} finally {
if ((inboxFolder != null) && (inboxFolder.isOpen())) {
try {
inboxFolder.close(true);
} catch (MessagingException e) {
log.error(e.getMessage(), e);
}
}
if ((store != null) && (store.isConnected())) {
try {
store.close();
} catch (MessagingException e) {
log.error(e.getMessage(), e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当尝试使用 javax.email 接收电子邮件时,这是 try-catch 的最后一部分,它同时抱怨 if 条件。
这是这些变量的声明,它们在 try 部分被实例化:
Folder inboxFolder = null;
Store store = null;
Run Code Online (Sandbox Code Playgroud)
那么为什么 SonarQube 会抱怨这个呢?
我想知道我是否可以在这里以某种方式轻松获得if语句:
public Object[] tableItemFromVisit(Visit visit, boolean editable) {
return new Object[] {
visit.getIdVisit(),
visit.getProfession().getProfessionName(),
visit.getSpiProfessional().getFullName(),
RegularFunctions.getTimeFormat().format(visit.getVisitDate()),
RegularFunctions.toNormalCapitalizedText(visit.getVisitState()
.toString()), visit.getReason(),
if (editable) { "Edit" },
};
}
Run Code Online (Sandbox Code Playgroud)
这个结构怎么称呼?数组规范还是什么?无论如何,如果变量"editable"为真,它必须有一个"编辑"字符串,如果它是假的,它不需要任何东西......显然我不想写两个太过类似的返回语句彼此...
好吧,我将首先展示我的代码:
@Override
public void init() throws ServletException {
super.init();
try {
securityController = SecurityControllerFactory.getInstance().create();
} catch (Exception e) {
System.err.println("Error creating security controller; " + e.getMessage());
}
// max allowed uploaded uploadedFile size is 10 MB
maxFileSize = getBytes(10);
maxMemSize = getBytes(2);
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,编译器迫使我使用try/catch来实例化SecurityController.但就我而言,我认为如果无法实例化安全控制器,它应该停止实例化Servlet并抛出异常.对此有何建议/解释?
我的 Tomcat 有一个很糟糕的问题,很糟糕,因为这个问题我已经放弃了这个项目一个多月了......但我仍然需要解决它并继续这个项目......
所以它给我这个错误:
java.sql.SQLException:找不到适合 jdbc 的驱动程序:sqlserver://isd.ktu.lt:1433;DatabaseName=LN2012_bakDB2 java.lang.NullPointerException
问题是相同的应用程序在桌面版本 Perfectlz 中运行,但是当涉及到应该在服务器上运行的版本(NetBeans 7.1.2 中的 Tomcat 7.0.22.0)时,它只会抛出错误。似乎它没有加载池驱动程序,或者我什至不知道......
好吧,这是负责的部分:
public DatabaseConnection(Parameters params) {
// parameters and the output
this.gui = params.getGui();
// activate database pool
connectionPool = new GenericObjectPool(null);
connectionFactory = new DriverManagerConnectionFactory(params.getDbAdr(), params.getDbUser(), params.getDbPass());
poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
driver = new PoolingDriver();
driver.registerPool("GenTreeDatabase", connectionPool);
//driver.registerPool("jdbc:apache:commons:dbcp:GenTreeDatabase", connectionPool);
}
public void openConn() {
if (allowOutput) gui.print("Getting connection to database");
try {
con = DriverManager.getConnection("jdbc:apache:commons:dbcp:GenTreeDatabase");
if (con != null) { …Run Code Online (Sandbox Code Playgroud) 我似乎看到了一些例子,人们通过添加CSS代码回答问题如何从组件中获取某些特定行为,但似乎没有人解释如何使用该CSS代码将其连接到Java组件......
.v-table-body{
overflow: hidden !important;
}
Run Code Online (Sandbox Code Playgroud)
我如何在我创建的表上使用此代码?
Table table = new Table(caption);
table.addContainerProperty("Visit ID", Long.class, null);
Run Code Online (Sandbox Code Playgroud) 我在我的Web应用程序中遇到此问题,我通过Tomcat执行基于表单的身份验证,并将其重定向到徽标图像文件,而不是重定向到包含该徽标图像的index.html文件...
我要去:
http://localhost:8080/GenTreeUploader/Servlet
Run Code Online (Sandbox Code Playgroud)
然后它给了我登录表单并且在成功登录后,我不在那个URL中,但是我被重定向到:
http://localhost:8080/GenTreeUploader/images/gdia_logo.png
Run Code Online (Sandbox Code Playgroud)
我去的时候经过身份验证后:
http://localhost:8080/GenTreeUploader/Servlet
Run Code Online (Sandbox Code Playgroud)
然后我被重定向到正确的位置而不是图像文件.
我正在附加我的web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<!-- WELCOME FILE LIST -->
<welcome-file-list>
<welcome-file>/Servlet</welcome-file>
</welcome-file-list>
<!-- Security -->
<security-constraint>
<web-resource-collection>
<web-resource-name>Wildcard means whole app requires authentication</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>tomcat</role-name>
</auth-constraint>
<user-data-constraint>
<!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE -->
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/error.html</form-error-page>
</form-login-config>
</login-config>
<!-- Main Servlet -->
<servlet>
<servlet-name>GenTreeUploaderServlet</servlet-name>
<servlet-class>org.ktu.gdia.presentation.web.GenTreeUploader</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GenTreeUploaderServlet</servlet-name>
<url-pattern>/Servlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
60
</session-timeout> …Run Code Online (Sandbox Code Playgroud) 期望似乎对我不起作用:
package com.jjs.caf.library.client.drafting;
import static org.junit.Assert.*;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
import com.jjs.caf.library.client.CustomerManager;
import com.jjs.caf.library.client.UserBookLimiter;
public class DraftTest {
UserBookLimiter userBookLimiter;
int expected = 5;
@Before
public void setUp() throws Exception {
userBookLimiter = EasyMock.createMock(UserBookLimiter.class);
EasyMock.expect(userBookLimiter.getMaxNumberOfBooksAllowed()).andReturn(5);
}
@Test
public final void test() {
assertEquals(expected, userBookLimiter.getMaxNumberOfBooksAllowed());
}
}
Run Code Online (Sandbox Code Playgroud)
它应该是5,但我得到0,好像期望不会在那里...
我真的很困惑,它将使用Adobe CQ5(Adobe Experience Manager)做什么工作?它是编程还是只是使用一些GUI,工具等,因为它毕竟是一个CMS?
我有机会参加这个CQ5高级开发人员培训,然后去找一份与之相关的工作:http: //training.adobe.com/training/courses/cq5-advanced-developer.html
我基本上想成为一名Java开发人员/程序员,我很困惑.这是给我的吗?或者它只是一些工具而不是很多编程?那是什么样的工作?
请帮助我,我很困惑,我必须很快做出决定.先感谢您.
好吧,我把这个logging.properties配置文件放到我的web apps src目录中:
handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
org.apache.juli.FileHandler.level = FINE
org.apache.juli.FileHandler.directory = ${catalina.base}/logs
org.apache.juli.FileHandler.prefix = GenTree.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
Run Code Online (Sandbox Code Playgroud)
但我找不到我在日志中输出的任何东西,除了控制台,并且没有任何文件以GenTree*开头的任何地方......有人知道这件事吗?据我所知,它可能使用了tomcat使用的jre的默认设置.但我想要这个项目的项目特定设置.
我的意思是我应该如何设置日志记录?我错过了什么吗?tomcats server.xml中有关于登录的内容,我应该修改它吗?我的意思是在关于登录tomcat的任何文章中都没有找到关于在server.xml中修改的任何内容.但是现在Tomcat看起来似乎是loggin这个模式,在server.xml中描述:
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下吗?
编辑:我已经检查了JRE目录(JAVA_HOME),它根本没有任何logging.properties ...
好的,所以如果我需要在构造函数中放入一些原始值,我该怎么做?
@Autowired
public CustomBean(String name, @Qualifier("SuperBean") SuperBean superBean) {
super();
this.superBean = superBean;
this.name = name;
}
Run Code Online (Sandbox Code Playgroud)
例如,我在这里定义superBean有限定符"SuperBean",但我也想知道如何使用注释在这里设置名称值?
我知道有可能使用xml配置,但我想知道如何使用注释执行此操作:
<bean id="CustomXmlBean" class="org.arturas.summerfav.beans.CustomXmlBean">
<constructor-arg name="name" type="String" value="The Big Custom XML Bean" />
<constructor-arg>
<bean id="SuperBean" class="org.arturas.summerfav.beans.SuperBean" />
</constructor-arg>
</bean>
Run Code Online (Sandbox Code Playgroud)
那么我如何为String,int和其他泛型类型输入值?
java spring dependency-injection spring-annotations constructorargument