Mini articles/java unknown stack trace (#11627)

* unknown source in stack trace

* Improved comment

* creating an intentional exception

Co-authored-by: Sameer <d7495b5879fca1ec1367476a5395a60a8e9baec9>
This commit is contained in:
Sameer 2021-12-28 22:36:17 +05:30 committed by GitHub
parent 5a5714b9f6
commit 7d4fd180d8
3 changed files with 54 additions and 0 deletions

View File

@ -24,6 +24,22 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>
<!-- Comment the arg below to print complete stack trace information -->
<!-- <arg>-g:none</arg>-->
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<h2.version>1.4.191</h2.version>
</properties>

View File

@ -0,0 +1,25 @@
package com.baeldung.unknownsourcestacktrace;
import com.baeldung.unknownsourcestacktrace.dto.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static final int SHORT_NAME_LIMIT = 10;
public static void main(String[] args) {
User user = new User();
user.setName("Tom");
logger.info(getGreetingMessage(user.getName()));
}
private static String getGreetingMessage(String name) {
return "Welcome " + getShortenedName(name) + "!";
}
private static String getShortenedName(String name) {
return name.substring(0, SHORT_NAME_LIMIT);
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.unknownsourcestacktrace.dto;
public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}