Question: I am trying to clean up html code in alot of HTML files, basically what we want is remove all Paragraphs from within specific Div classes 

I am trying to achieve this within powershell and got as far as finding the block of text to replace and remove the opening P and closing P tags within this text, but having troubles getting the updated text back in the HTML file

I have hundreds of files that contain one or more of these blocks 

```html
<div class="SomeClass">
    <p various attributes>
    HTML formatted content
    </p>
</div>

```

What is the easiest way to update all .htm files such that the `<P>` tags within the "SomeClass" classes have been cleaned.

What I have now is 

```bsh
$htmlCode = Get-Content $Testfile
$firstString = '<div class="SomeClass">'
$secondString = '</div>'
$pattern = "$firstString(.*?)$secondString"

$result = [regex]::Match($htmlCode, $pattern).Groups[1].Value

$cleanedHtml = $result -replace '<p[^>]+>',''
$cleanedHtml = $cleanedHtml -replace '</p>',''

$newHtmlCode = $htmlCode -replace $result, $cleaned

```

When I run this the `$newHtmlCode` contains the original code. I'm having troubles getting the old block replaced by the new block.

Answer: 
`Objects.requireNonNull`
========================

As others noted, you should [check that incoming argument](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Objects.html#requireNonNull(T,java.lang.String)) is not null. 

```
public TSTLocalDate dateToTSTLocalDate(Date date) {     
    Objects.requireNonNull( date , "Opps, received a NULL rather than a Date object. Message # e99b92a3-da0b-419b-9f93-8cfee36a757b." ) ;
…

```

You have other problems.

Time zone
=========

The `Date` represents a moment in UTC. Determining a date requires a time zone. For any given moment the date varies around the globe by zone. 

But your code ignores this crucial issue of time zone. The `Calendar` class (actually `GregorianCalendar`) implicitly uses the JVM’s current default time zone when you neglect to provide one. So your results may vary. Better to always specify explicitly your desired/expected time zone. 

*java.time*
===========

Another problem: You are using terrible date-time classes that were supplanted years ago by the modern *java.time* classes.

Convert your `java.util.Date` to `Instant`, both classes representing a moment in UTC. 

```
Instant instant = myJavaUtilDate.toInstant() ; 

```

Specify your desired/expected zone. 

```
ZoneId z = ZoneId.of( "America/Montreal" ) ;
ZonedDateTime zdt = instant.atZone( z ) ; 

```

Extract the date-only portion, without time-of-day, and without time zone. 

```
LocalDate ld = zdt.toLocalDate() ;

```

You can interrogate the `LocalDate` for its year, month, and day. 

You can generate strings in various formats representing the value of the `LocalDate` by using `DateTimeFormatter`. 

---

![Table of date-time types in Java, both modern and legacy.](https://i.stack.imgur.com/V7t6V.png)
On the 2nd line in the exception, there is probably the exact line in which it happens:

> 
> TSTHoliday.dateToTSTLocalDate(TSTHoliday.java:**145**)
> 
> 
> 

called by

> 
> TSTHoliday.java:**42**
> 
> 
> 

Check if the `date` object passed to this method is null, something like this:

```
TSTLocalDate tSTLocalDate;
if(date != null) {
    tSTLocalDate = dateToTSTLocalDate(date);
}

```

And in the method you may add a check for null:

```
public TSTLocalDate dateToTSTLocalDate(Date date) {     

    if(date == null) {
        Log.d("TAGLOG", "Error date null in dateToTSTLocalDate");
    }
    else {
        this.calenderDate.year = date.getYear();            
        this.calenderDate.month = date.getMonth();          
        this.calenderDate.day = date.getDay();
    }

    return this.calenderDate;
}

```