Threads of a string or stringy threads? That's the question

  • 24
  • Locked
1. The getPartOfString method must return the substring between the first and the last tab characters. 2. The getPartOfString method should throw an exception if it receives invalid data: a) StringForFirstThreadTooShortException if the thread's name is FIRST_THREAD_NAME.
You can't complete this task, because you're not signed in.
Comments (6)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Justin Smith
Level 38 , Greenfield, USA, United States
11 December 2021, 22:50
Task is hard enough to figure out what it wants, but there is also one major part of it that's not even hinted at in the conditions. You need to build the constructors for the two exceptions. The way they set up the intended output also makes for really poor code efficiency. Why would any project ever want the three components of the exception message to be in different orders depending on what type of exception it is? This would have been a good opportunity to consolidate everything into one message handling method where all three things are in the same order but have different output depending on the arguments passed. The way this task is currently set up, it's equally code-efficient to just return the literal strings that the validation requires (though it won't pass validation). Basically I feel that this task is encouraging poor programming behavior and poor project planning.
Thành Black
Level 49 , Hanoi
18 October 2021, 07:55
it hard to understand this task.
Level 24 , Wittenberg, Germany
8 June 2021, 18:06
If it weren't for the helpful posts by null and Rom I wouldn't have been able to get my submission past the broken validator. However is responsible for the awful task specification and the even more awful submission validation code should be treated according to the following rules: 1) If their job contract specifies something like 'xxx USD' than they should be paid xxx unwashed, scratched dimes (because that is also consistent with the abbreviation 'USD'); if it says 'dollars' then they should be paid an amout of xxx in cheapest legal tender anywhere in the world that also goes by the name of 'dollar'. 2) Their salary should be paid out by a member of the International Space Station, only aboard said space station, only to the payee in person. Should the ISS resupply schedule be incompatible with the pay schedule then I suggest a dead drop somewhere in Antarctica or safe dropped into the Mariana trench.
Ian De Bie Full Stack Developer
8 November 2020, 17:31
the task conditions for this exercise is like reading a foreign language: gobbledygoop a) 1# : StringForFirstThreadTooShortException : java.lang.StringIndexOutOfBoundsException: String index out of range: -1 b) java.lang.StringIndexOutOfBoundsException: String index out of range: -1 : StringForSecondThreadTooShortException : 2# c) RuntimeException : java.lang.StringIndexOutOfBoundsException: String index out of range: -1 : 3#
Level 26 , Orlando, United States
28 July 2020, 20:03
protected String getFormattedStringForOtherThread(Thread t, Throwable e, String string) { return String.format(string, e.getClass().getSimpleName(), e.getMessage(), t.getName()); } getName() call showing null in console output, but I got passed.
Level 26 , Paris, France
24 March 2021, 13:32
To correct this, you use constructor in your exception class :
public class StringForFirstThreadTooShortException extends RuntimeException {
    StringForFirstThreadTooShortException(String s) {
then,in your solution class you pass the message :
if (threadName.equals(Solution.FIRST_THREAD_NAME)) throw new StringForFirstThreadTooShortException("java.lang.StringIndexOutOfBoundsException: String index out of range: -1");
            else if (threadName.equals(Solution.SECOND_THREAD_NAME)) throw new StringForSecondThreadTooShortException("java.lang.StringIndexOutOfBoundsException: String index out of range: -1");
            else throw new RuntimeException("java.lang.StringIndexOutOfBoundsException: String index out of range: -1");